title: Using ClientValidationFunction (JavaScript) in an UpdatePanel
body: <p>I'm trying to determine why my validation function is not being called on my web form.  I've read through various articles at <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx" rel="nofollow">MSDN</a> and most notably found this nugget.</p>
  
  <blockquote>
    <p>When you use the CustomValidator control inside an UpdatePanel control, 
    make sure that the validator control and the control it is associated with 
    are in the same panel. For more information about using the UpdatePanel 
    control for partial-page updates, see <a href="http://msdn.microsoft.com/en-us/library/bb386573.aspx" rel="nofollow">Partial-Page Rendering</a> Overview.</p>
  </blockquote>
  
  <p>With this knowledge I modified my code as follows:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel0" runat="server"&gt;
      &lt;ContentTemplate&gt;
          &lt;script type="text/javascript"&gt;
              function IsNotChecked(obj, args) {
                  args.IsValid = false;
                  if (document.getElementByID("cbRegion0").checked) 
                  {
                      args.IsValid = true; return true; 
                  }
                  return false;
               }
          &lt;/script&gt;
          &lt;asp:CheckBox ID="cbRegion0" runat="server" ValidationGroup="0" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged" /&gt;
          &lt;asp:CustomValidator ID="CustomValidator0" runat="server" ValidationGroup="0" ClientValidationFunction="IsNotChecked" ErrorMessage="You did not check the box." ValidateEmptyText="True" /&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>The issue I'm having is that the validation routine does not get executed when clicking the submit button on my page.
  Some unique elements of the design is that the code above is actually inside of a .ascx that is added to the page via <code>Control.Add()</code> but I don't see how that would affect the ClientValidationFunction.  I believe it's related to the placement of the <code>&lt;script&gt;</code> inside the form but despite following directions at <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx" rel="nofollow">MSDN</a> it doesn't seem to have made a difference. 
  Thanks for any ideas!</p>