views:

371

answers:

1

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(
    &quot;ctl00$wpm$CheckoutPage$ctl02$ContinueButton&quot;, &quot;&quot;, true, 
    &quot;OPC&quot;, &quot;&quot;, 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(
   &quot;ctl00$wpm$CheckoutPage$ctl02$ContinueButton&quot;, &quot;&quot;, true, 
   &quot;OPC&quot;, &quot;&quot;, false, false))" style="border-width:0px;" />
    <br /><br />
  </td>
</tr>
A: 

You have

...return false; WebForm_DoPostBackWithOptions...

in your OnClientClick so WebForm_DoPostBackWithOptions is never called in your second example.

algiecas
Thanks. That certainly can be a problem. The Validators are now called, but Is_PageValid is still returns true. Here's my JS: function disableSubmit() { if (typeof (Page_ClientValidate) == 'function') { if (Page_IsValid != null } else { return true; } } else { return DoSomething(); } }Why is Is_PageValid set to true?