Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web User Controls and Validation

I have an ASP.Net web user control that contains a TextBox and a calendar from the Ajax Control Toolkit.

When I include this user control on my page I would like it to participate in input validation (there is a required filed validator set on the TextBox inside the UC), ie. when the page is validated the content of the UC should also be validated. So I had my UC implement the IValidator interface, which worked well except that I could not set the validation group on the user control. Apparently I'm supposed to inherit from BaseValidator to do that, but I can't since I'm already inheriting UserControl.

There's got to be a way to deal with this common scenario.

like image 464
Xavier Poinas Avatar asked Dec 11 '08 13:12

Xavier Poinas


People also ask

What are the validation controls?

ASP.NET validation controlsIt is used to compare the value of an input control against a value of another input control. It evaluates the value of an input control to check the specified range. It evaluates the value of an input control to determine whether it matches a pattern defined by a regular expression.

What is validation in web?

In simple terms, validation ensures that your website complies with the standards accepted by most web designers. That also means that it will be accessible to more people, across more web browsers and operation systems. Having an accessible website is also regarded as good web design practice.


1 Answers

You can reference a control within a user control by seperating the two with a dollar sign:

<asp:RequiredFieldValidator ControlToValidate="MyUserControl$ControlId" runat="server" />
like image 147
Sjoerd Avatar answered Oct 12 '22 18:10

Sjoerd