WalterHeisenberg
Technical User
- Mar 28, 2008
- 159
Hello,
I have a wizard which has a few textboxes for customers to enter a start/stop date and a regular expression in place to ensure they enter it in the proper format. I also added a custom validator to test the date. Although the validation test is failing (confirmed by responsewriting args.IsValid) the page proceeds to fire the wizard_nextbuttonclick event which writes to db and blows up since there is bad data. Any help would be greatly appreciated!
Here is code (omitting non-relevant stuff):
aspx:
code behind:
I have a wizard which has a few textboxes for customers to enter a start/stop date and a regular expression in place to ensure they enter it in the proper format. I also added a custom validator to test the date. Although the validation test is failing (confirmed by responsewriting args.IsValid) the page proceeds to fire the wizard_nextbuttonclick event which writes to db and blows up since there is bad data. Any help would be greatly appreciated!
Here is code (omitting non-relevant stuff):
aspx:
Code:
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Date fields do not have valid values." OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
code behind:
Code:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (DateTime.TryParse(startDate, out datetime) == true && DateTime.TryParse(endDate, out datetime2) == true)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}