Please give advice on itt . also want if date invalid it should same page plus .use whatever break do not excute more
code inside button click event if date is not valid
protected void btn_ok_Click(object sender, EventArgs e)
{
//DateTime dt = new DateTime();
//dt = Convert.ToDateTime(tb_age.Text);//"2011-12-30"
//TimeSpan ts = DateTime.Now.Subtract(dt);
//int y = ts.Days / 365;
DateTime dtStart = DateTime.Parse(tb_age.Text);
TimeSpan sp = DateTime.Now - dtStart;
if (sp.Days < 18 * 365)
{
Response.Write("<script>alert('Age not validated. You are year old.')</script>");
tb_age.Focus();
}
else { Response.Write("<script>alert('Age valid')</script>"); }
Label1.Visible = true;
Label1.Text = " Why are you runnning in button click if not valid age if valid than ok ";
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Visible = false;
}
Collapse | Copy Code
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<h4>Date format must be like :07/01/1989(MM/DD/YYYY)</h4>
<asp:TextBox ID="tb_age" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="MM/dd/yyyy" TargetControlID="tb_age">
</asp:CalendarExtender>
<asp:Button ID="btn_ok" runat="server" Text="Test Age" onclick="btn_ok_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>