TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Valerie Meunier
NA
693
82.9k
why does the program not stop?
Apr 17 2021 11:10 AM
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();
}
Reply
Answers (
2
)
Unicode Language in Vb6.0. not working properly
string was not recognized as a valid dateTime.