Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<div>
        <asp:TextBox ID="txt_startdate" runat="server"><asp:TextBox ID="txt_enddate"
            runat="server"><asp:CompareValidator ID="CompareValidator1"
ControlToValidate="txt_enddate" Type="Date" Operator="GreaterThan"
ErrorMessage="invalid"
ControlToCompare="txt_startdate" runat="server" ForeColor="Red" 
            ValueToCompare="txt_enddate">
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label">
        <br />
        <asp:TextBox ID="TextBox1" runat="server">
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="TextBox1" ErrorMessage="required" ForeColor="Red">
    </div>


my code abobe i want if 6jun-2013 is start date then end date must be 07jun2013 onword not below than current date
Posted
Updated 5-Jun-13 21:28pm
v3
Comments
pramodachary 6-Jun-13 3:07am    
Hi
fist add datepicker to text control and use .AddDays(1) and populate in enddate texbox..

Hi

fist add datepicker to text control and use .AddDays(1) and populate in enddate texbox..
 
Share this answer
 
You can use asp compare validator for this purpose.. for example if you have two textboxes i.e txtDateStart & txtEndDate and you want to validate them user can not enter end date which comes before start data.. mean 7th june should not be start date if 6 june is end date.

Following is the sample code.
XML
<asp:CompareValidator ID="ValidatorID1" runat="server" ControlToCompare="txtStartDate" ControlToValidate="txtEndDate" ErrorMessage="Start Date must be before End Date" Operator="GreaterThan" Type="Date" Display = "None"></asp:CompareValidator>

Hope it will help.

Regards, :)
 
Share this answer
 
v2
Comments
BHABANI PRASAD DASH 6-Jun-13 3:45am    
display none property i think doesnt display eroor.actually ur code is not working properly
VICK 6-Jun-13 7:08am    
Because display is set to none so to display the error,, you have to place that validation control under validation summary.. so that it could be called properly.

for reference see the link below,

http://www.w3schools.com/aspnet/control_comparevalidator.asp
BHABANI PRASAD DASH 6-Jun-13 7:13am    
i dont have validation summary
VICK 6-Jun-13 7:17am    
Just put the following in your design page. validation summary will be called when you will try to redirect from page.. ie.. when u try to click on submit type button to proceed the page. and validation summary will show all the validators from the page on a single page. which is also gud to manage the design.

<asp:ValidationSummary id="valSum" DisplayMode="BulletList" EnableClientScript="true"
HeaderText="Errors occured in the following fields:" runat="server"/>


for further reference see the link below....

http://www.w3schools.com/aspnet/control_validationsummary.asp
 lang="xml">DateTime a = DateTime.Parse(txt_enddate.Text);
       DateTime b = DateTime.Parse(install_date.Text);

       if (a > b)
       {
           ScriptManager.RegisterClientScriptBlock(updfee, 
updfee.GetType(), "Hello", 
"alert('installment date should not greater than 
dispatch date');", true);
          // 
Response.Write("<script>alert('installment
 date should not greater than dispatch 
date');</script>");
           install_date.Text = "";
           dispatch_date.Text = "";
       }
 
Share this answer
 
You can use CompareValidator[^] to compare the date. Try this:
ASP.NET
<asp:CompareValidator Operator="GreaterThan" Type="Date"
    ControlToValidate="TextBox1" ControlToCompare="txt_startdate"
    ErrorMessage="End date should be greater than start date." runat="server" /></asp:CompareValidator>




--Amit
 
Share this answer
 
v2

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