Last Reply on Apr 25, 2012 04:58 AM By Amit

Posted on Apr 12, 2012 12:06 AM

How can i check that a perticular date selected from calendar control is already past....

suppose i select 2/2/2010 then a message will be shown that oops!  date u selected, already past

Posted on Apr 12, 2012 12:06 AM

How can we find whether this date is selected in past?

Posted on Apr 12, 2012 02:46 AM

I want to compare a selected date from calendar control with my system date and if my selected date is previous date compare to my system date ,i want to show that day(my selected date from calendar control) is in past.......... so how to coampare?? what to do? plz help.....

Posted on Apr 16, 2012 07:11 AM


Try this code i given below.

//Declare a text box which is hidden in aspx page.


 <div style="display: none;">

<asp:TextBox ID="hdnTodaysDate" runat="server" Text="11/10/2011"></asp:TextBox>


In your page load, use this code in code behind.

// Here i am assigning current system date to the text box.

 hdnTodaysDate .Text  = DateTime.Now.ToString("MM/dd/yyyy");

Use the CompareValidator to compare your date with the given date.

use the below code in aspx page. 


 <asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server" ControlToCompare="hdnTodaysDate" ControlToValidate="txtDOB"  ErrorMessage="Please enter valid date."                                             Operator="LessThan" ValidationGroup="vgUserRegistration" Type="Date"></asp:CompareValidator>


Happy coding.



Posted on Apr 25, 2012 04:58 AM

Below code check date selected by U through calander control,if it already passed then it show alert date already passed else show date in textbox...............

IN .aspx page :

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged1"  ></asp:Calendar>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


In .vb page


 Protected Sub Calendar1_SelectionChanged1(ByVal sender As Object, ByVal e As System.EventArgs)

        If Calendar1.SelectedDate < System.DateTime.Now Then
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "amit", "alert('Date Already passed');", True)
            Exit Sub
            TextBox1.Text = Calendar1.SelectedDate
        End If
    End Sub