From Date Should Be Greater than To Date Check In asp.net
From Date Should Be Greater than To Date Check In asp.net
Step :1 Design web from .aspx page
<div>
<asp:ScriptManager ID="sm" runat="server">
</asp:ScriptManager>
From
<asp:TextBox ID="txtFrom"
runat="server"
OnTextChanged="txtFrom_TextChanged"
AutoPostBack="true"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender2"
runat="server"
PopupButtonID="txtFrom"
Enabled="True"
TargetControlID="txtFrom"
ClearTime="True"
TodaysDateFormat="MM/dd/yyyy"
Format="MM/dd/yyyy">
</cc1:CalendarExtender>
<br />
To<asp:TextBox ID="txtto" runat="server"
OnTextChanged="txtto_TextChanged"
AutoPostBack="true"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1"
runat="server"
PopupButtonID="txtto"
Enabled="True"
TargetControlID="txtto"
ClearTime="True"
TodaysDateFormat="MM/dd/yyyy"
Format="MM/dd/yyyy">
</cc1:CalendarExtender>
</div>
Step 2: Logic on .Cs apge
protected void
txtFrom_TextChanged(object sender, EventArgs e)
{
ChkDate();
}
protected void
txtto_TextChanged(object sender, EventArgs e)
{
ChkDate();
}
public void ChkDate()
{
DateTime a = new DateTime();
DateTime b = new DateTime();
a = Convert.ToDateTime(txtFrom.Text);
if (string.IsNullOrEmpty(txtto.Text))
{
}
else
{
b
= Convert.ToDateTime(txtto.Text);
if (a < b)
{
}
else
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"Alert", "alert('From
Date Is greater Than To date!');", true);
}
}
}
}
Comments
Post a Comment