Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disabling Automatic Validation on CompareValidator (VB.NET)

    So my project site has really been off and rolling, but I have discovered one of those weird hitches that seemed to have an easy answer... having a small problem with comparevalidators and regular expression validators.

    Many of the forms on the site have several text boxes that are required, and a few that are subject to regular expression validation (phone numbers, zip codes etc). The desired effect is that validation does not take place until the submit button is pressed. Setting every text box's "causesvalidation" property to false seems to do the trick for requiredfield validators, but any compare validators (i.e. for matching passwords when creating a new account) will fire the instant that a text box is changed, regardless of whether that text box is set to cause validation or not.

    I could do the validation in the submit button's onclick event, but that would kind of defeat the purpose of having the "easy to use" validator controls... I have tried enabling or disabling the validator controls in the onclick event, (i.e. you fill out the form, click the submit button and then all of the validator controls are activated and checked), but the same overzealous validation happens again once the page is presented again. (since the validation controls were enabled)

    This seems to be overcomplicated. So far as I can tell, there is no property of the validator itself that would take care of this problem. Do I need to go old school and write my own validation or is there simply some property or value that I am overlooking?

    Thanks!

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling Automatic Validation on CompareValidator (VB.NET)

    If you don't mind a postback, you can set the EnableClientScript property to false. This will force the validation to be performed on the server.

    One of my employers required a lot of server-side logic, so I found myself almost always setting all validators to be run on the server (many were CustomValidators). As long as your page is fast, this shouldn't be a problem for most users.

    In addition, I'm not a huge fan of the Microsoft client-side validation that comes with .NET... I've used it and will continue to do so, but something just rubs me wrong with all of the little caveats - such as the one you've mentioned.

    Let me know how the EnableClientScript = false setting works!

    Afterthought... I think the compare validators are are not working with the client-side validation you've established since they generally require at least two elements to be in place before they can work. I'm guessing this is one of those design caveats I mentioned above...

  3. #3
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling Automatic Validation on CompareValidator (VB.NET)

    Yeah, I know what you mean. For my comparevalidator control, I am comparing two password fields to make sure they match when someone creates a new account. The instant you put in your password the first time and hit tab to get to the "verify password" field, the validator fires and tells you that they must match.... sort of a "duh" statement.

    So I have a caveat for your caveat-- if enableclientscript is false, what happens if one of my pages requires other things like those java event-driven buttons or calendar controls or pagination etc etc... would it disable that sort of functionality as well..?
    Generally I have noticed that MS' attempts at simplifying things ends up making them pretty hairy in the end... [img]/forums/images/smilies/smile.gif[/img]

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling Automatic Validation on CompareValidator (VB.NET)

    Good question - nope, the EnableClientScript attribute only applies to the object who's property you're setting. It will not affect any other objects (or validators, for that matter) on the page that use client-side scripting (either custom or from MS).

  5. #5
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling Automatic Validation on CompareValidator (VB.NET)

    So will it still have the same validation effect, just executed on the server side?
    I had seen a page that used EnableClientScripting (as false) in a more global sense, maybe in a page directive, which is why I thought it may affect other parts of the page.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •