IValidator and ValidationGroup

Discussion in 'ASP .Net Web Controls' started by Giorgio Parmeggiani, Apr 18, 2007.

  1. Hi

    I have a custom control which inherit from IValidator, ASP.NET 2.0, how can
    i define a ValidationGroup for my custom WebControl? In the IValidator interface
    i have not found a ValidationGroup property!

    Thanks for any suggestion

    Giorgio
     
    Giorgio Parmeggiani, Apr 18, 2007
    #1
    1. Advertising

  2. Hi Giorgio,

    As for the "ValidationGroup", it is a new feature added in ASP.NET 2.0, and
    the IValidator interface has been defined in ASP.NET 1.X and hasn't be
    modified in .net framework 2.0. However, for ASP.NET valiation controls,
    they all derive from the "BaseValidator" class(abstract class which
    implement the IValidator interface) , and this class has defined a public
    virtual "ValidationGroup" property. Therefore, your custom validator can
    derive from this abstract base class:

    #BaseValidator.ValidationGroup Property
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalid
    ator.validationgroup.aspx

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Apr 19, 2007
    #2
    1. Advertising

  3. Hi Steven

    Thank for your reply

    Unfortunately i can not derive my webcontrol from "BaseValidator" because
    it inherit from "TextBox", do you think i can use some workaround to solve
    my problem?

    Giorgio

    > Hi Giorgio,
    >
    > As for the "ValidationGroup", it is a new feature added in ASP.NET
    > 2.0, and the IValidator interface has been defined in ASP.NET 1.X and
    > hasn't be modified in .net framework 2.0. However, for ASP.NET
    > valiation controls, they all derive from the "BaseValidator"
    > class(abstract class which implement the IValidator interface) , and
    > this class has defined a public virtual "ValidationGroup" property.
    > Therefore, your custom validator can derive from this abstract base
    > class:
    >
    > #BaseValidator.ValidationGroup Property
    > http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.bas
    > evalid ator.validationgroup.aspx
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx
    > #notif ications.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent
    > issues where an initial response from the community or a Microsoft
    > Support Engineer within 1 business day is acceptable. Please note that
    > each follow up response may take approximately 2 business days as the
    > support professional working with you may need further investigation
    > to reach the most efficient resolution. The offering is not
    > appropriate for situations that require urgent, real-time or
    > phone-based interactions or complex project analysis and dump analysis
    > issues. Issues of this nature are best handled working with a
    > dedicated Microsoft Support Engineer by contacting Microsoft Customer
    > Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    Giorgio Parmeggiani, Apr 19, 2007
    #3
  4. Thanks for your reply Giorgio,

    After some further research, I'm afraid for developing custom Validator
    control in ASP.NET, you should use the "BaseValidator" class and IValidator
    interface is just a simple interface which can help you get reference to a
    certain validation control and call the validation method.

    I've also checked the ASP.NET page's code logic and in the Page's
    server-side validation processing stage, it will get all the validators on
    page through a "BaseValidator" control collection, therefore, if your
    custom valicator is not derived from "BaseValidator", the page runtime will
    ignore it.

    ====code logic from disassembled page class===
    public ValidatorCollection GetValidators(string validationGroup)
    {
    if (validationGroup == null)
    {
    validationGroup = string.Empty;
    }
    ValidatorCollection validators = new ValidatorCollection();
    if (this._validators != null)
    {
    for (int i = 0; i < this.Validators.Count; i++)
    {
    BaseValidator validator = this.Validators as BaseValidator;
    if (validator != null)
    {
    if (string.Compare(validator.ValidationGroup,
    validationGroup, StringComparison.Ordinal) == 0)
    {
    validators.Add(validator);
    }
    }
    else if (validationGroup.Length == 0)
    {
    validators.Add(this.Validators);
    }
    }
    }
    return validators;
    }
    ========================

    Would you provide some further information on why you need to make your
    custom validator inherit from TextBox? Generally validator will validate
    other controls and display error info, so a Label parent class is expected.
    Is there any particular requirement that you need to also input some value
    for the validator control?

    Please feel free to let me know your concern and we can try looking for
    some other means to resolve it.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Apr 23, 2007
    #4
  5. Hi Giorgio,

    How are you doing on this, does the further information helps a little? Or
    if you have any other concerns and requirement that we can try
    investigating further? 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], Apr 25, 2007
    #5
  6. Hi Steven,

    Thanks for your reply, this is my problem:

    I have a WebControl which imitate a TextBox (it have some functionality:
    caption property, automatic decoding, etc....).
    My WebControl inherit from System.Web.Controls.Control, i would validate
    it using a standard validator, but, from the designer, in the "ControlToValidate"
    property of standard validator i can not see my custom WebControl

    So i thought to encapsulate the validation functionality into my WebControls,
    but i have the problem of "IValidator" and i can not inherit from "BaseValidator"


    So: I can use a standard validator to valid a control which inherit from
    System.Web.Controls.Control?

    Thanks in advance

    Giorgio


    > Hi Giorgio,
    >
    > How are you doing on this, does the further information helps a
    > little? Or if you have any other concerns and requirement that we can
    > try investigating further? 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.
    >
     
    Giorgio Parmeggiani, Apr 26, 2007
    #6
  7. Hi Giorgio,

    Thanks for your reply.

    Actually for developing custom webcontrol which need to be validatable by
    other controls, you should use "ValidatePropertyAttribute" to specify a
    property(of your custom control) which is validatable by other validators.
    You can refer to the following knowledge base article for details:

    #How to extend a Web form control to work with the validation controls by
    using Visual C#
    http://support.microsoft.com/kb/310145/en-us

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Apr 30, 2007
    #7
  8. Hi Giorgio,

    Still any further question or does the information in last reply helps?
    Please feel free to let me know 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], May 3, 2007
    #8
  9. Hi Steven

    Excuse for the delay

    Your suggestion has been very precious, I have understood whether to resolve
    the problem

    Thanks
    Giorgio

    > Hi Giorgio,
    >
    > Still any further question or does the information in last reply
    > helps? Please feel free to let me know 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.
    >
     
    Giorgio Parmeggiani, May 21, 2007
    #9
    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. =?Utf-8?B?QS5KLiB2YW4gZGVyIEJ1cmc=?=

    Validationgroups and IValidator problem (ASP.NET 2.0)

    =?Utf-8?B?QS5KLiB2YW4gZGVyIEJ1cmc=?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,628
    =?Utf-8?B?QS5KLiB2YW4gZGVyIEJ1cmc=?=
    Dec 9, 2005
  2. brantman

    Ivalidator and Validation Groups

    brantman, Jul 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,141
    Teemu Keiski
    Aug 1, 2006
  3. =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?=

    Ajax, and MaskEdit, ValidationGroup

    =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?=, Apr 17, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    653
    =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?=
    Apr 17, 2007
  4. Shark Bait

    TextBox:IValidator and a star (*)

    Shark Bait, Oct 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    194
    Phillip Williams
    Oct 21, 2005
  5. A.J. van der Burg

    Validation groups and IValidator problem (ASP.NET 2.0)

    A.J. van der Burg, Dec 9, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    192
    A.J. van der Burg
    Dec 9, 2005
Loading...

Share This Page