Validators on dynamic UserControls

Discussion in 'ASP .Net' started by rgparkins@hotmail.com, Feb 20, 2006.

  1. Guest

    Hi

    I am currently having problems with Validators in a user control. I am
    creating a wizard sign-up process which have the allocated step
    (hyperlinks" at the top of the page. A user can also click
    next/previous. Dependant on the current step in the sign-up process I
    am loading a new user control as I dont want to have 7-8 pages, just
    one page and load the control dynamically.

    All is sweet at the moment apart from the validation controls that are
    assigned to each user control. Any link that is clicked or button that
    is clicked should cause validation on that user control, however I have
    performed the following (from another thread)

    1. Set EnableClientScript=false on each validator.
    2. Set CausesValidation=false on each button that submits the page.
    This
    prevents the Page.Validate() method from begin called automatically by
    the
    button.
    3. In your click event method, you will call the Validate() method on
    each
    validator that is associated with the submit button. Then you will test
    the
    IsValid property to be true on each validator before saving.

    I am performing this process BUT as I loop on each validate control
    with the allocated user control the isValid IS ALWAYS true. I am sure
    its something to do with not loading something or just a simple step I
    have missed.. I would appreciate any help on this, some code:

    private bool Persist() {
    //first check whether we have valid data
    AddStockCommon ctrl =
    (AddStockCommon)this.FindControl(String.Format("{0}{1}",
    ViewState["Context"], ".ascx"));

    foreach(Control ct in ctrl.Controls) {
    if (ct is BaseValidator) {
    BaseValidator validator = (BaseValidator)ct;
    validator.Validate();

    if (!validator.IsValid) {
    return false;
    }
    }

    return true;
    }


    Many thanks

    Richard
     
    , Feb 20, 2006
    #1
    1. Advertising

  2. Guest

    OK

    To anyone out there..... Further investigations yielded no solutions
    until I decided to make the validators visible (They were set invisible
    as I wanted a summary to appear only).

    Setting them Visible suddenly made the client side validators work on
    the browser, but I have to say that this looks clunky and totally
    unusable, (mabe my designer could do something :))

    I am now going to do my own checks on the server upon a post back, as
    this will say me time understanding these validators which to all
    intents and purposes seem like a last minute thought to .NET 1.1.

    I hope they have improved on .NET 2.0, and if anyone can either point
    me in the right direction then I'll maybe return to this validation
    technique but for now its easier (on the eye and technically) to
    perform all validation server side...

    If anyone can tell me why setting these validators Invisible affects
    how they work then I would be glad to hear.

    Many thanks

    Richard
     
    , Feb 21, 2006
    #2
    1. Advertising

  3. webonomic Guest

    Check out the image in this article. They talk about the same thing,
    that the validation summary is ugly.

    http://www.codeproject.com/aspnet/vsum.asp

    There may be a solution here as well
    http://www.asp101.com/articles/manu/validationsummary/default.asp

    jp


    wrote:
    > OK
    >
    > To anyone out there..... Further investigations yielded no solutions
    > until I decided to make the validators visible (They were set invisible
    > as I wanted a summary to appear only).
    >
    > Setting them Visible suddenly made the client side validators work on
    > the browser, but I have to say that this looks clunky and totally
    > unusable, (mabe my designer could do something :))
    >
    > I am now going to do my own checks on the server upon a post back, as
    > this will say me time understanding these validators which to all
    > intents and purposes seem like a last minute thought to .NET 1.1.
    >
    > I hope they have improved on .NET 2.0, and if anyone can either point
    > me in the right direction then I'll maybe return to this validation
    > technique but for now its easier (on the eye and technically) to
    > perform all validation server side...
    >
    > If anyone can tell me why setting these validators Invisible affects
    > how they work then I would be glad to hear.
    >
    > Many thanks
    >
    > Richard
     
    webonomic, Feb 22, 2006
    #3
  4. Peter Blum Guest

    By definition, when any web control has Visible=false, that turns off the
    control. It will not generate anything to the client-side. It isn't a style
    that shows and hide things. (Besides the validators have the job of showing
    and hiding themselves.) Since the validator is off when Visible=false, the
    call to Validator.Validate() or even Page.Validate() will do nothing to the
    validator.

    Recommendation: Use Validation Groups, one for each page. This comes with
    ASP.NET 2.0 and my Professional Validation And More
    (http://www.peterblum.com/vam/home.aspx) which works with all versions of
    ASP.NET.

    >>> Setting them Visible suddenly made the client side validators work on
    >>> the browser, but I have to say that this looks clunky and totally
    >>> unusable, (mabe my designer could do something :))


    If you set EnableClientScript=false on each validator, there should be no
    client-side validation. Confirm these settings.
    What does "looks clunky" mean? One guess is that validators are changing
    their spacing on the screen, moving things around. Use
    Validator.Display=Static or set the Text property to "*" and add a
    ValidationSummary to show the actual error.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    <> wrote in message
    news:...
    > Hi
    >
    > I am currently having problems with Validators in a user control. I am
    > creating a wizard sign-up process which have the allocated step
    > (hyperlinks" at the top of the page. A user can also click
    > next/previous. Dependant on the current step in the sign-up process I
    > am loading a new user control as I dont want to have 7-8 pages, just
    > one page and load the control dynamically.
    >
    > All is sweet at the moment apart from the validation controls that are
    > assigned to each user control. Any link that is clicked or button that
    > is clicked should cause validation on that user control, however I have
    > performed the following (from another thread)
    >
    > 1. Set EnableClientScript=false on each validator.
    > 2. Set CausesValidation=false on each button that submits the page.
    > This
    > prevents the Page.Validate() method from begin called automatically by
    > the
    > button.
    > 3. In your click event method, you will call the Validate() method on
    > each
    > validator that is associated with the submit button. Then you will test
    > the
    > IsValid property to be true on each validator before saving.
    >
    > I am performing this process BUT as I loop on each validate control
    > with the allocated user control the isValid IS ALWAYS true. I am sure
    > its something to do with not loading something or just a simple step I
    > have missed.. I would appreciate any help on this, some code:
    >
    > private bool Persist() {
    > //first check whether we have valid data
    > AddStockCommon ctrl =
    > (AddStockCommon)this.FindControl(String.Format("{0}{1}",
    > ViewState["Context"], ".ascx"));
    >
    > foreach(Control ct in ctrl.Controls) {
    > if (ct is BaseValidator) {
    > BaseValidator validator = (BaseValidator)ct;
    > validator.Validate();
    >
    > if (!validator.IsValid) {
    > return false;
    > }
    > }
    >
    > return true;
    > }
    >
    >
    > Many thanks
    >
    > Richard
    >
     
    Peter Blum, Feb 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Hamm
    Replies:
    1
    Views:
    465
  2. Ratman
    Replies:
    0
    Views:
    679
    Ratman
    Sep 14, 2004
  3. Replies:
    1
    Views:
    955
  4. Nathan Sokalski

    Using Validators to validate UserControls

    Nathan Sokalski, Sep 5, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    300
    Nathan Sokalski
    Sep 5, 2008
  5. Nathan Sokalski

    Using Validators to validate UserControls

    Nathan Sokalski, Sep 5, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    122
    Nathan Sokalski
    Sep 5, 2008
Loading...

Share This Page