title: Future date validation in asp.net using javascript
body: <p>Below mentioned code is been used to validate a future date, but it's not working. Any help is appreaciated.
   The textbox has readonly property set to false so i can change the values in the text box and change to the future date,for that condition i need to validate</p>
  
  <p><strong>// In aspx</strong> </p>
  
  <pre><code>  &lt;asp:TextBox ID="txtdob" runat="server" OnClientDateSelectionChanged="checkDate"&gt;&lt;/asp:TextBox&gt;
  
    &lt;asp:Button ID="Button2" runat="server" onclick="Button2_Click" Height="26px" Width="23px" Text=".." /&gt;   
  &lt;script type="text/javascript" &gt;
  function checkDate(sender, args) 
  {
      if (sender._selectedDate &gt; new Date())
      {
          alert("You cannot select future date!");
          sender._selectedDate = new Date();
          // set the date back to the current date
          sender._txtdob.set_Value(sender._selectedDate.format(sender._format))
      }
  }
  &lt;/script&gt;
  &lt;asp:Calendar ID="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged" OnClientDateSelectionChanged="checkDate"
     style="top: 320px; left: 246px; position: absolute; height: 188px; width: 259px"&gt;
  &lt;/asp:Calendar&gt;
  </code></pre>
  
  <p><strong>//In c#</strong></p>
  
  <pre><code>protected void Button2_Click(object sender, EventArgs e)
  {
     Calendar1.Visible = true;
  }
  protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  {
     txtdob.Text = Calendar1.SelectedDate.ToShortDateString();
  }
  </code></pre>