New Version added via SVN 12/11/2008 in Source Code tab. Contains an example using the code inside a custom control.

Project Description
This control is built on top of the ASP.NET AJAX Control Toolkit and is designed to extend the ASP.NET RequiredFieldValidator control.

It extends the RequiredFieldValidator control by setting the CSS for a required control if it is invalid. It also extends a label control associated with the required control.

For instance, if you have a form where you have a textbox that is required and that textbox has a ASP.NET RequiredFieldValidator control applied to it, you can use this control to set the textbox's CSS property should the RequiredFieldValidator indicate the textbox is empty. When the form is submitted, if the textbox is empty, your CSS class will be applied to the textbox client-side. You can also specify that a label control have your custom CSS class applied to it as well.

This control is built on top of Microsoft's AJAX Control Toolkit. It extends the behavior of an ASP.NET RequiredFieldValidator control to apply a CSS class to the control being validated if it is invalid (client side). It also will apply a CSS class to an ASP.NET Label control as well. For example, say you have a textbox on your ASP.NET page that is required such a name textbox:

image1.png

If the user submits the form with an empty textbox, the result will be that the textbox and label will have the CSS class you specify applied to them. In my case, I wanted them to show in red:

image2.png

And here is a screenshot of the ASP.NET Markup used to create the sample above:

image3.png

With this control, all you need to do to add your custom CSS to a required field is to reference the assembly in your ASP.NET project, register the control in your web.config file, and then add the RequiredFieldExtender as shown above to your ASP.NET Markup. The control can be used against any control being validated with a RequiredFieldValidator control such as TextBox, RadioButtonList, DropDownList, etc.


http://www.brentlamborn.com

Last edited Dec 11, 2008 at 5:21 PM by BrentLamborn, version 8