Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Validator not preventing processing

Status
Not open for further replies.

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:
 <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;
        }
     }
 
In the 'wizard_nextbuttonclick' Event, you should have some code that looks like this:

Code:
if (CustomValidator1_ServerValidate.IsValid)
    {
    // Submit the Form
    }
else
    {
    // Don't Submit the Form
    }

HTH

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
DOH ! Sorry, it should be:

Code:
if (CustomValidator1.IsValid)
    {
    // Submit the form
    }
else
    {
    // Don't Submit the form
    }

C.

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Thanks very much. This did the trick. For some reason I was under the impression the custom_validator control would cancel the request inherently if it failed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top