title: Server side variable in client side custom validator
body: <p>I have a custom validator on a page:</p>
  
  <pre><code>&lt;asp:CustomValidator ID="CustomValidator2" runat="server"  
       ControlToValidate="ddlProposer" ErrorMessage="Please select some values."  
       Display="Dynamic" onservervalidate="CustomValidator2_ServerValidate" 
       ClientValidationFunction="CustomValidator2_ClientValidate"&gt;
  &lt;/asp:CustomValidator&gt;  
  </code></pre>
  
  <p>It must be valid, when a server-side list is not empty (or: the <code>ListCount</code> variable > 0). This list may change after the page has been loaded (via buttons on update panel):</p>
  
  <pre><code>public partial class Pages_Application_Application : System.Web.UI.Page
  {
      protected List&lt;IdValue&gt; ProposersList
      {
          get
          {
              if (ViewState["proposersList"] == null)
                  ViewState["proposersList"] = new List&lt;IdValue&gt;();
              return ViewState["proposersList"] as List&lt;IdValue&gt;;
          }
          set
          {
              ViewState["proposersList"] = value;
          }
      }
  
      public int ListCount
      {
          get
          {
              return this.ProposersList.Count;
          }
      }
  ...
  </code></pre>
  
  <p>There is no problem with server-side validation:  </p>
  
  <pre><code>protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
  {
      args.IsValid = this.ProposersList.Count &gt; 0;
  }
  </code></pre>
  
  <p>The problem is with client-side part. I've been trying something like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function CustomValidator2_ClientValidate(source, arguments) {
          var serverVariable = &lt;%= ListCount %&gt;;
          alert(serverVariable);
          arguments.IsValid = serverVariable &gt; 0;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>however, it fires only on first page load, and the ListCount variable is always 0 (so does the serverVariable).  </p>
  
  <p>The question is: is there an easy-way to make it working? So the Javascript gets the <strong>current</strong> value of some server-side variable?</p>