|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IValidator and ValidationGroupHi
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 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. 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 Show quote > 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. > 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[i] 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[i]); } } } 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. 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. 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 Show quote > 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. > 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. |
|||||||||||||||||||||||