title: Get control in javascript
body: <p>I have a couple of textboxes that will contain dates only. If one textbox has a date and the user tries to submit without entering a date in the other date textbox they will be stopped before submit. The way I want to do this is with the following javascript function:</p>
  
  <pre><code>function ClientValidate(sender, args) {
         // Get Both form fields
         var txtdate1 = document.getElementById('&lt;%=txtdate1.ClientID%&gt;');
         var txtdate2 = document.getElementById('&lt;%=txtdate2.ClientID %&gt;');
  
      // do you client side check to make sure they have something
         if (txtdate1.value != '' &amp;&amp; txtdate2.value == '') {
  
          args.IsValid = false;
      }
      else
      {
          args.IsValid = true;
      }
      if (txtdate2.value != '' &amp;&amp; txtdate1.value == '') {
  
          args.IsValid = false;
  
      }
      else {
          args.IsValid = true;
      }
  }
  </code></pre>
  
  <p>The creation of the textboxes and date stuff is as follows.</p>
  
  <pre><code>Dim bttndate1 As New ImageButton
      bttndate1.ID = "bttndate1"
  
      Dim txtdate1 As New TextBox
      txtdate1.ID = "txtdate1"
      txtdate1.Width = 65
  
      Dim calex1 As New AjaxControlToolkit.CalendarExtender
      calex1.TargetControlID = "txtdate1"
      calex1.Format = "MM/dd/yyyy"
      calex1.PopupButtonID = "bttndate1"
  
      '**************** date box2 ***************
  
      Dim bttndate2 As New ImageButton
      bttndate2.ID = "bttndate2"
      bttndate2.Style.Add("cursor", "pointer")
  
      Dim txtdate2 As New TextBox
      txtdate2.ID = "txtdate2"
      txtdate2.Width = 65
  
  
      Dim calex2 As New AjaxControlToolkit.CalendarExtender
      calex2.TargetControlID = "txtdate2"
      calex2.Format = "MM/dd/yyyy"
      calex2.PopupButtonID = "bttndate2"
  </code></pre>
  
  <p><strong>Here is the Validator</strong>       </p>
  
  <pre><code>    Dim custval As New CustomValidator
      custval.ID = "ValidPage"
      custval.ClientValidationFunction = "ClientValidate"
      custval.ErrorMessage = "You Must Enter a 'From' Date and a 'To' Date"
      custval.ErrorMessage = "You Must Select a Vendor"
      custval.SetFocusOnError = True
      custval.ControlToValidate = "txtdate1"
      custval.EnableClientScript = True
  </code></pre>
  
  <p><strong>MY problem is that the javascript isn't finding the two textboxes because i create them in code</strong>
   any ideas?</p>