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 it 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 set up 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 …
Other post in ASP.NET
- ASP.NET GridView Edit All Rows At Once - October 30th, 2007
- Validating A WebForms Checkbox . . . - January 4th, 2008
- ListView and the DataPager - January 7th, 2008
- The case of the disappearing session variables - January 14th, 2008
- Storing a DataRow into a Session (server) variable - January 15th, 2008
- The point of a multi layer architecture - January 31st, 2008
- FormView Edit and Add - May 12th, 2008
- Virtual Files using HttpContext.RewritePath() - July 17th, 2008
- ASP.NET AJAX using JSON - Here's how. - August 4th, 2008
- SystemException: The trust relationship between the primary domain and the trusted domain failed - November 18th, 2008
- GridViews - Multiple Rows Per Record - December 17th, 2008
- Response.Redirect() executes too soon on the Server. - January 27th, 2009
- Tab Control ActiveTabIndex Lost on Postback - February 25th, 2009
- ASP.NET Application_Error Detecting 404's - March 2nd, 2009
- Infinite 302 Loop - How would you even know? - March 11th, 2009
- Unable to find connection...for object web.config - March 18th, 2009
- Dynamically Change class Attribute From ASP.NET - September 29th, 2009
- HttpContext.Items vs Session - October 12th, 2009
- Access a control by ID From Within a Databound Control - November 2nd, 2009
- GridView and Updating A Row Manually - November 4th, 2009
- Embedding Google Search Appliance Results in ASP.NET - November 5th, 2009
- ASP.NET Cross Domain Form Submission - November 11th, 2009
- ASP.NET Interview Questions For New College Graduates - November 12th, 2009
- ASP.NET Dynamic Validator - November 16th, 2009
- The Google Appliance and Forms Authentication - August 4th, 2010
- Prevent Postback on Buttons - October 11th, 2010
- Azure CDN Blob Storage Case Sensitive Issue - April 17th, 2012
- ASP.NET JSON and ViewState - September 25th, 2012
- Panel DefaultButton does not work - December 25th, 2012
- Why CSS ID selectors are Evil in ASP.NET Web Forms - February 26th, 2013
- Sorting the ListView in ASP.NET - March 5th, 2013
- Multi-Step Processing in ASP.NET - May 8th, 2013
- ASP.NET Web Design Software - May 15th, 2013
- Test Sending Email without a Server in ASP.NET - June 5th, 2013
- Tracking Down Performance Issues in ASP.NET - July 24th, 2013
- Unrecognized Tag Prefix or Device Filter ‘asp’ - July 31st, 2013
- WebServices – Error Handling - December 11th, 2013
- Converting a DataList to a ListView - December 25th, 2013