title: how to add dynamic custom client side validator in asp.net
body: <p>i have textbox controls that are created dynamically in the ASP.NET. I want to add dynamically custom validators for these controls. These validators should be run on the client side. I have the following code snippet: </p>
  
  <pre><code>    protected override void InitDynamicControls()
      {
          registerScript();
  
          CustomValidator cv = new CustomValidator();
          cv.ErrorMessage = "error";
          cv.Display = ValidatorDisplay.Dynamic;
          cv.ControlToValidate = TextField.ID;
          cv.ValidationGroup = "ConfigurationValidation";
          cv.ClientValidationFunction = "ConfigurationOption_ClientValidate";
  
          base.Controls.Add(cv);
      }
  
  
      private void registerScript()
      {
          System.Text.StringBuilder script = new System.Text.StringBuilder();
  
          script.Append("&lt;script language=\"javascript\"&gt;\n");
          script.Append("function ConfigurationOption_ClientValidate(source, arguments) \\{arguments.IsValid = false;\\}\n");
          script.Append("&lt;/script&gt;\n");
  
          Type type =  this.GetType();
  
          if (!Page.ClientScript.IsClientScriptBlockRegistered(type, "ConfigurationOption_ClientValidate"))
              Page.ClientScript.RegisterClientScriptBlock(type, "ConfigurationOption_ClientValidate", script.ToString());
      }
  </code></pre>
  
  <p>The method in the javascript will contain the logic. Method InitDynamicControls() is loaded in  Page_Load method. When I click the button on the page the validator doesn't run.</p>
  
  <p>can you help me what can be wrong?
  thanks</p>