ASP.NET Dynamic Validator


misc_vol3_100

One of the controls that was added to ASP.NET 3.5 in the SP1 release was the Dynamic Validator control.

I completely missed it.

What is does is pretty cool.  But, it doesn’t really do what you’d think it might.  Or at least not what I thought it would.  “Dynamic” implies to me some kind of hook up to the database.  But the Dynamic Validator control doesn’t hook to the database.  At least not directly.  What it does, however, is a lot more flexible.

You would use the Dynamic Validator control in a lot of the same instances that you’d use the Custom Validator.  While the Custom Validator has a lot more flexibility, the Dynamic Validator is a bit easier to implement.

The Dynamic Validator displays any exceptions that the OnChanging event of a field in your datasource.  This allows you to put all of your validations in the OnChanging event of the control rather than an event handler of the Custom Validator.

To demonstrate, place a TextBox control and a Dynamic Validator control on your page and set the ControlToValidate property to point to the TextBox control.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:dynamicvalidator runat="server" ID="dynamicValidator"
   ControlToValidate="TextBox1"></cc1:dynamicvalidator>

You’ll need to setup some sort of databinding between the text box and a datasource because the validation happens at the field level, not at the display level.

To implement the validations, create an OnFieldChanging event handler of a partial class that represents the row you’ve bound for the field the TextBox is bound to and create some sort of check.  Throw an exception if the check fails.

The validation control will then pick up the exception and display it for you.

Other places talking about the DynamicValidator control

Passing Arguments to a Dynamic Data Field Template from a UIHint … -  The ASCX is pretty basic. All that is here is my UI control and the needed validation controls. … Generic Access to ASP.NET Dynamic Data UIHint Attribute Values. Friday, May 09, 2008 1:01 PM by Craig Shoemaker. Yesterday I published a post titled, Passing Arguments to a Dynamic Data Field Template from a UIHint …

custom validation and business logic in asp.net dynamic data using … – the exception that is raised by this code will be caught and displayed to the user by the dynamicvalidator control located in the corresponding dynamic field template. the field template in this case is the integer_edit.ascx file, …

Ads by Lake Quincy Media

Other Related Items:

MCTS Self-Paced Training Kit (Exam 70-562): Microsoft .NET Framework 3.5-ASP.NET Application Development: Microsoft(r) .Net Framework 3.5 ASP.Net Application Development (Pro - Certification)MCTS Self-Paced Training Kit (Exam 70-562): Microsoft .NET Framework 3.5-ASP.NET Application Development: Microsoft(r) .Net Framework 3.5 ASP.Net Application Development (Pro - Certification)

Ace your preparation for the skills measured by MCTS Exam 70-562—and on the job. Work at your own pace through a series of lessons and reviews... Read More >

Don't Mess With Me, I am a Programmer - T-Shirt (40 colors)Don't Mess With Me, I am a Programmer - T-Shirt (40 colors)Cotton T-Shirt 5.6 oz., heavyweight 100% preshrunk cotton T-shirt, Quarter-turned. Seamless collar, Taped shoulder-to-shoulder, Double-needle stitched neck, sleeves and hemmed bottom. Direct printed on Front of T-Shirt, this is not a transfer. Won't peel or crack in washer/dryer.

Related Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor