Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Restrict the user to enter further dates in textbox in asp.net c#
========================================================================

Dear Frnds,

I have Two Textboxes on my webpage. I need to enter From and To Dates into the Textboxes.

For Example I need to enter FromDate : 30/08/2012 ToDate : 25/10/2012

so my requirement is ToDate should not be less than FromDate and FromDate should not be Greater than ToDate.

if the user enter other than these two dates,,,,it must show a error

Please help.....

I need the code in these events
C#
protected void TxtFromDate_TextChanged(object sender, EventArgs e)
    {

    }


C#
protected void TxtToDate_TextChanged(object sender, EventArgs e)
    {

    }



Please help Thanks in Advance
Posted
Comments
[no name] 30-Aug-12 10:20am    
So how much are you paying for someone to write this code for you? How are you going to be paying them?

Hi,

I am not going to write this code but ofcourse i will guide you how can you do that.

You can use Compare/Custom Validation Control for that. This[^] example show you how can you call a server side function. Even you can write javascript to validate your date.

Hope you can do it. As i have already given an example in the link
Thanks
-Amit Gajjar
 
Share this answer
 
Comments
Christian Amado 30-Aug-12 10:56am    
5'ed :) You can use RegularExpressionValidator for date input too, plus the controls explain by @amitgajjar =)
AmitGajjar 30-Aug-12 11:07am    
thanks Christian Amado :)
Use Copmare Validator for validation in following way its solved your problem.....

XML
<asp:TextBox runat="server" ID="MyTextBoxFromDate"></asp:TextBox>

<asp:TextBox runat="server" ID="MyTextBoxToDate"></asp:TextBox>

 <asp:CompareValidator  ID="CompareValidator1" runat="server" ErrorMessage="Date range not       valid." ControlToCompare="MyTextBoxFromDate" ControlToValidate="MyTextBoxToDate"             ValueToCompare="MyTextBoxFromDate" Operator="GreaterThanEqual" Type="Date"          ValidationGroup="NameofGroup"></asp:CompareValidator>
 
Share this answer
 

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