Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is like first coffee in the winter morning..."

Geography

Where in the world do Tek-Tips members come from?

Custom Validator not preventing processing

WalterHeisenberg (TechnicalUser)
4 Jun 10 13:29
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;
        }
     }
ChewDoggie (Programmer)
6 Jun 10 13:49
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.

ChewDoggie (Programmer)
6 Jun 10 13:54
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.

WalterHeisenberg (TechnicalUser)
6 Jun 10 18:08
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close