0

I have a calendar control assigned to a textbox

I would like to know how to do the on change of the date and check if it matches todays date. if it matches a button would be enabled if it wont match the button would be disabled.

Here is the code of the asp.net page

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    Date&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtStartDate" runat="server" Height="22px" Width="234px"></asp:TextBox> 
    <asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtStartDate" runat="server">
    </asp:CalendarExtender>  

this is the code i have come up with so far but dont know where to place it or if it is also correct

        string today = DateTime.Now.ToShortDateString();
        txtStartDate.Text = CalendarExtender1.SelectedDate.ToString();

        if (txtStartDate.Text != today)
        {
                btn_Search.Enabled = false;
        }
        else
        {
            btn_Search.Enabled = true;
        }

I am working on an asp.net project page Thanks

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Dennis Vella
  • 21
  • 3
  • 4

2 Answers2

0

You would need to hook it up with event OnClientDateSelectionChanged. Similar example explained here well CalendarExtender Change date with Javascript

Community
  • 1
  • 1
Subhash Dike
  • 1,836
  • 1
  • 22
  • 37
0
// calculating date difference, if it is zero days
if ((CalendarExtender1.SelectedDate - DateTime.Now).TotalDays == 0)
{
        btn_Search.Enabled = false;
}
else
{
    btn_Search.Enabled = true;
}
Waqas Raja
  • 10,802
  • 4
  • 33
  • 38