Hi
When i leave the field 'begdat' (of a gridview in editing mode) empty or with anything except date , i get the error 'Not a date 1' and i'm compelled to fill a valid date. The error "Not a date 2." at line 16 is never shown.
Now, if i remove lines 13 to 17 and i leave the field empty or with anything except date, line 18 gives this error "String was not recognized as a valid DateTime". This is what i don't understand. Normally, the program would be stopped at line 4. How come that line 4 now is ignored and that the program goes further?
Thanks.
- protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
- GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
- TextBox begdattxt = (TextBox)row.FindControl("begdat");
- if (!DateTime.TryParse(begdattxt.Text,out newDate))
- {
- e.Cancel = true;
- ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", " alert('Not a date 1.');", true);
- }
- else
- {
- begdat = Convert.ToDateTime(e.NewValues["begdat"]);
- }
- ....
- else if (!DateTime.TryParse(begdattxt.Text, out newDate) || !DateTime.TryParse(enddattxt.Text, out newDate))
- {
- e.Cancel = true;
- ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", " alert('Not a date 2.');", true);
- }
- else if (Convert.ToDateTime(enddattxt.Text) < Convert.ToDateTime(begdattxt.Text))
- {
- flag = "1";
- e.Cancel = true;
- Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", " alert('endate must be >= begindate.');", true);
- enddattxt.Focus();
- }