title: Creating text & button controls dynamically and populating text box with date values
body: <p>I currently have a VB.Net application that builds textboxes dynamically.<br>
  I need to display a button control which will display a datepicker and then populate the corresponding textbox with the selected date value.  </p>
  
  <p>I am creating the btnCalendar dynamically since there are more than one calendar buttons on a particular page, so <code>btnCalendar.ID = tab.ID &amp; grdRowID</code>    </p>
  
  <pre><code>Protected Sub DisplaySearchWindow()
  Dim ddl As DropDownList
  Dim txt As TextBox
  Dim cal As Calendar
  Dim btnCalendar As Button 
  
  Select Case iIndex
    Case 1
       Dim cv As New CompareValidator
       txt = New TextBox
       txt.ID = "txt" &amp; UserName &amp; grdRowID.Name
       cv.ControlToValidate = txt.ID
       btnCalendar = New Button
       btnCalendar.ID = "btnCalDisplay" &amp; tab.ID &amp; grdRowID
       btnCalendar.Text = "+"
       btnCalendar.ToolTip = "click to view calendar" 
       btnCalendar.Attributes.Add("OnClientClick", "javascript:return ShowAlert('Hi');")
       c.Controls.Add(cv)
       c.Controls.Add(txt)
       c.Controls.Add(btnCalendar)
  </code></pre>
  
  <p>When building the button control in codebehind, I have <code>btnCalendar.OnClientClick = btnCalendar.Visible = True</code>  </p>
  
  <p>When I run the application and click btnCalendar, I get an error message <strong>JavaScript runtime error: 'True' is undefined</strong>.  </p>
  
  <p>How can I display the DatePicker control using btnCalendar.OnClientClick (or any other alternative) from codebehind ?</p>