How to incorporate IsValid in a non-ASP.NET (standard html) approach button
<p>I know that ASP.NET controls such as the button have the postback event model.  And checking whether the page.IsValid is dependent on events and postback in order for the validation to kick in.</p>

<p>But what if I have a button using regular HTML  inside my .aspx (and I don't want to use the asp.net button...please do not ask me why) yet still want to take advantage of calling Page.IsValid?</p>

<p>For example, lets say my .aspx page has 2 buttons:</p>

<pre><code>&lt;asp:ImageButton runat="server" ID="cmdPlaceOrder" OnClick="cmdPlaceOrder_Click" ImageUrl="images/someButton.gif" /&gt;
</code></pre>

<p>and that was there in the page, someone else had created that a while back.  In the cmdPlaceOrder we check for Page.IsValid:</p>

<pre><code>protected void cmdPlaceOrder_Click(object sender, EventArgs args)
{

    if (!IsValid)
        return;
    ... rest of logic
}
</code></pre>

<p>That's standard.  Now what if I add a non-ASP.NET button like this in the .aspx page, used to place the order (but for a different kind of order seperate from the existing place order button above):</p>

<pre><code>&lt;a href="&lt;%=SomeUrl() %&gt;"&gt;&lt;img src="images/buttonPayGoogleCheckout.gif" alt="Pay with Google"/&gt;&lt;/a&gt;
</code></pre>

<p>So on click of the hyperlink, the page posts back to itself (same url).  I check the url for a querystring param flag that if set calls the method below that I created which is basically a similar method as the above but with a bit of different logic in it:</p>

<pre><code>protected void PlaceGoogleCheckoutOrder()
{

    if (!IsValid)
        return;
    ... rest of logic here, but I can't get to it because there is no event model to allow IsValid to work
}
</code></pre>

<p>Obviously I'm not tying in an event model to this therefore once it hits the check for Page.IsValid it errors with the following message at runtime:</p>

<pre><code>Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate.
</code></pre>

<p>But I still want to be able to call this validation, the validation that's already been setup in our .aspx.  I don't want to reinvent the wheel on this and I don't in this case want to use an ASP.NET based button (do not ask me why, I have my reasons and it's too long to get into that).</p>

<p>I want to know how I can still get that Page.IsValid check to work for a non-event driven button using .  I'm not sure how to hook up an event to do so that still hooks in after the redirect and allows that code to still validate.</p>

<p>I tried adding Page.Validate(); inside my PlaceGoogleCheckoutOrder() method right before the check for Page.IsValid but I still get the same error.</p>

<p>After looking at MSDN on Page.Validate() (<a href="http://msdn.microsoft.com/en-us/library/0ke7bxeh.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/0ke7bxeh.aspx</a>) and it states "The validation group is determined by the control that posted the page to the server. If no validation group is specified, then no validation group is used."</p>

<p>So that's why nothing happened.  So I'm not sure how to get ASP.NET in this case to know about the control (in this case my ) that posted the page to the server so that a validation group IS used.  I guess I could add a runat="server" to my ...but doubt that's all I need to do here.</p>
