Accessing the ControlToValidate control in a Validator

Discussion in 'ASP .Net' started by Nathan Sokalski, May 20, 2008.

  1. I am writing a Validator by inheriting from the BaseValidator class. I need
    to access the control referred to by the ControlToValidate property. Because
    ControlToValidate is a String, I will need to use the FindControl() method
    using ControlToValidate as the argument. In most cases, this would work
    perfectly fine, but as most of us know, there are some scenarios (such as
    those involving Master pages) in which the NamingContainers can make this
    harder than we would like. The GetControlValidationValue() method obviously
    needs to reference the ControlToValidate control when it gets the validation
    value, so I am wondering if there is some hidden way to make it easier to
    get the ControlToValidate control in a Validator, since they are often used
    together. Any help would be appreciated. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, May 20, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    bruce barker Guest

    the validator design logic requires the validator and the control to be
    validated are in the same naming container. There is no hidden logic, the
    base validator code just does a this.NamingContainer.FindControl().

    if you know the fully qualified path you can specify it as:
    parent1$parent2$child

    you could make your own naming container that the validators were placed in
    that had its own FindControl logic.


    -- bruce (sqlwork.com)


    "Nathan Sokalski" wrote:

    > I am writing a Validator by inheriting from the BaseValidator class. I need
    > to access the control referred to by the ControlToValidate property. Because
    > ControlToValidate is a String, I will need to use the FindControl() method
    > using ControlToValidate as the argument. In most cases, this would work
    > perfectly fine, but as most of us know, there are some scenarios (such as
    > those involving Master pages) in which the NamingContainers can make this
    > harder than we would like. The GetControlValidationValue() method obviously
    > needs to reference the ControlToValidate control when it gets the validation
    > value, so I am wondering if there is some hidden way to make it easier to
    > get the ControlToValidate control in a Validator, since they are often used
    > together. Any help would be appreciated. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
    bruce barker, May 20, 2008
    #2
    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. Steven Nagy

    Custom Control needs ControlToValidate

    Steven Nagy, Mar 6, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    594
    MasterGaurav \(www.edujini-labs.com\)
    May 8, 2007
  2. Nathan Sokalski
    Replies:
    0
    Views:
    351
    Nathan Sokalski
    Mar 8, 2010
  3. Donal McWeeney

    custom validator and ControlToValidate in a composite control...

    Donal McWeeney, Sep 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    219
    Donal McWeeney
    Sep 29, 2004
  4. Nathan Sokalski

    Accessing the ControlToValidate control in a Validator

    Nathan Sokalski, May 20, 2008, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    808
    bruce barker
    May 20, 2008
  5. Nathan Sokalski

    Accessing the ControlToValidate control in a Validator

    Nathan Sokalski, May 20, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    164
    bruce barker
    May 20, 2008
Loading...

Share This Page