I wrote a UserControl that attaches a Javascript function to a form's submit button. The Javascript function ensures that the page is valid by calling Page_IsValid
and then proceeds to execute some code. For the problematic pages, the Page_IsValid
is set to true on first load. If I don't set the OnClientClick, Page_IsValid
is correctly set to false on the first load. I can't figure out why Page_IsValid is behaving this way, since no events are being fired at all. Also, it only happens on some pages and not others. It seems this is only happening to pages that have the WebForm_DoPostBackWithOptions attached to their onclick events. Why would simply adding a click event make such a difference?
Here's my code:
Server side:
(control as Control).OnClientClick = "disableSubmit(); return false;";
Here's the code that gets generated:
Without OnClickEVent:
<input type="image" name="ctl00$wpm$CheckoutPage$ctl02$ContinueButton"
id="ctl00_wpm_CheckoutPage_ctl02_ContinueButton"
src="../images/continue.gif" alt="Continue"
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
"ctl00$wpm$CheckoutPage$ctl02$ContinueButton", "", true,
"OPC", "", false, false))" style="border-width:0px;" />
<br /><br />
</td>
With OnClickEvent:
<tr id="ctl00_wpm_CheckoutPage_ctl02_trContinue">
<td valign="top">
<div id="ctl00_wpm_CheckoutPage_ctl02_AddressValidationSummary"
class="validationSummary" style="color:Red;display:none;"></div>
<br />
<input type="image" name="ctl00$wpm$CheckoutPage$ctl02$ContinueButton"
id="ctl00_wpm_CheckoutPage_ctl02_ContinueButton" src="../images/continue.gif"
alt="Continue" onclick="disableSubmit();
return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
"ctl00$wpm$CheckoutPage$ctl02$ContinueButton", "", true,
"OPC", "", false, false))" style="border-width:0px;" />
<br /><br />
</td>
</tr>