title: How to pass control.ClientId to an OnClick function in ASP.NET?
body: <p>I'm trying to turn on/off various <code>RequiredFieldValidator</code> controls when checkboxes are checked/unchecked, based on this <a href="https://stackoverflow.com/questions/2132837/asp-net-make-a-textbox-required-if-a-checkbox-is-checked">question</a>. But rather than having a separate js function for each checkbox I want to pass in the ClientID of the input to validate, something like this (only one INPUT here but you can see once it's working I can add more INPUTs without more js): </p>
  
  <pre><code>&lt;asp:TextBox ID="txtSubject" runat="server" /&gt;
  &lt;asp:CheckBox ID="chkSubjectRequired" runat="server" 
      OnClick="updateValidator('&lt;%= rfvSubject.ClientID %&gt;');" /&gt;
  &lt;asp:RequiredFieldValidator ID="rfvSubject" ControlToValidate="txtSubject" 
      ErrorMessage="You must enter a subject." runat="server" /&gt;
  
   &lt;script&gt;
   function updateValidator(inputId) {
        var enableValidator = !event.srcElement.checked;
        var theInput = document.getElementById(inputId);
        ValidatorEnable(theInput, enableValidator);
   }
   &lt;/script&gt;
  </code></pre>
  
  <p>Currently that scriptlet <code>txtSubject.ClientID</code> isn't evaluated, just output directly. I'm sure this is simple but I just don't know the appropriate syntax.</p>