Click here to Skip to main content
15,883,819 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds,

am working on asp.net C#.

am creating an appointment progam using asp.net c#. It is Intranet Project.

On my webpage I have Calendar cotrol and a button.

Here, after selecting date from calendar control user clicks on button to redirect next page...till here its works fine.

But My requirement is, I want to Validate Calendar Control if user didnt select date and click on button....

I need message (Please Select Date)

Can this be possible to give validation for calendar control.

Please help.

Thanks.
Posted
Comments
Kornfeld Eliyahu Peter 16-Nov-14 5:54am    
Make the text box, calendar attached to required...

Check the below code

C#
<asp:calendar id="startCalendar" cssclass="startDate" onselectionchanged="Selection_Changed" runat="server" >
<asp:customvalidator id="dateCustVal" onservervalidate="DateCustVal_Validate" >
    runat="server">

protected void DateCustVal_Validate(object source, ServerValidateEventArgs args)
{            
    if (startCalendar.SelectedDate == null 
        || startCalendar.SelectedDate == new DateTime(0001, 1, 1, 0, 0, 0))
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }
}
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900