The best way to validate UserControls

Discussion in 'ASP .Net' started by Max2006, Jul 13, 2007.

  1. Max2006

    Max2006 Guest

    Hi,

    I have a user control that has a property named "Text"

    Is there any way that I use a RequiredFieldValidator or CompareValidator to
    validate my user control's value?

    I tried it and I received this error:

    Control 'cboCountry' referenced by the ControlToValidate property of
    'valCountry' cannot be validated.

    Thank you,
    Max
    Max2006, Jul 13, 2007
    #1
    1. Advertising

  2. Max2006

    Masudur Guest

    On Jul 13, 10:05 pm, "Max2006" <> wrote:
    > Hi,
    >
    > I have a user control that has a property named "Text"
    >
    > Is there any way that I use a RequiredFieldValidator or CompareValidator to
    > validate my user control's value?
    >
    > I tried it and I received this error:
    >
    > Control 'cboCountry' referenced by the ControlToValidate property of
    > 'valCountry' cannot be validated.
    >
    > Thank you,
    > Max


    Hi...

    i assume you have a control inside the usercontrol that receive input
    from user and you do want to validate the input ...
    here are the options you have...
    1. add the requited field validator for the input in the usercontrol
    rather that in the page...
    2. validate the text using server side validation... (for this you
    need to write a server side validation method...)

    Thanks
    Md. Masudur Rahman (Munna)
    kaz Software Ltd.
    www.kaz.com.bd
    http://munnacs.110mb.com
    Masudur, Jul 14, 2007
    #2
    1. Advertising

  3. Hi Max,

    Yes, I agree with Masudur's opinion. Also, if you do want to make Validator
    controls directly function against your ascx usercontrol, you can use the
    "ValidationPropertyAttribute" class to define a property to be validatable
    in your ascx control's code behind.

    #ValidationPropertyAttribute Class
    http://msdn2.microsoft.com/en-us/library/system.web.ui.validationpropertyatt
    ribute(VS.80).aspx

    Based on my test, through the intellisense not work, you can manually put
    usercontrol's ID to validateor's "ControlToValidate" property and so far it
    seems only server-side validation is working in this case.

    Anyway, I think Masudur's suggested approaches are still the preferred ones
    here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jul 16, 2007
    #3
  4. Hi Max,

    Have you got any further idea on this or does the information helps you
    some? Please feel free to post here if there is anything else we can help.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jul 18, 2007
    #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. Gummy
    Replies:
    0
    Views:
    320
    Gummy
    Sep 19, 2006
  2. Nathan Sokalski

    Using Validators to validate UserControls

    Nathan Sokalski, Sep 5, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    292
    Nathan Sokalski
    Sep 5, 2008
  3. JJA
    Replies:
    13
    Views:
    298
    John Saunders
    Jul 27, 2004
  4. Nay

    Best event to load usercontrols in ASP.NET 2.0

    Nay, Feb 25, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    104
  5. Nathan Sokalski

    Using Validators to validate UserControls

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

Share This Page