ASP CompareValidator and NOT submitting form
I have a textbox and a submit button. The textbox is a date-entry field.
Attached to it, I have a compare validator with the type set to "date". It does validate and show an error message.
Problem is, the user can still click on the submit butto开发者_开发问答n. I'd like to prevent that. If the user has entered something like 03/hello/2011, he or she should not be able to submit the form.
How can I accomplish this?
Any ideas?
Thanks,
Jason
Associate the validator and the submit button in a single validation group. Both of them have the property validation group. Provide a name say pageValidation to both the control's property.
I've encountered this problem myself, that a page with validation errors can still continue on to submission when the user clicks the submit button.
What you can do is something like this :
protected void submitClicked(object sender, EventArgs e)
{
if (!Page.IsValid)
{
// somehow the user was able to submit their form even though there are
// validation errors. Stop here and let ASP.NET present the error messages
// to the user
return;
}
// do submission stuff here like putting things in the database
}
精彩评论