Several Validation Controls are provided with the ASP.Net framework. The great thing about these controls, is that they can be used with little or no programming. Naturally, there are many properties which need to be populated, but compared to the old Javascript way of programming form fields, it is much easier with ASP.Net
Name :
ControlToValidate="txtName"
Display="Dynamic"
ErrorMessage="Must have a value entered!"
Runat="server">
The property 'EnableClientScript' enables the validator to run on the client side, and not require a postback to the server. 'ControlToValidate' merely 'hooks-up' the validation control to a particular form field. In this case, we are using an ASP.Net Textbox Server control named 'txtName'. The 'Display' property is really valuable. If you choose 'Dynamic' as the property value, then, valuable real estate on the page is saved. It only shows, if it fires and displays the message. Without assigning it's value as 'Dynamic', the space needed for the message will be visually blank at all times. And of course, 'ErrorMessage' is exactly what you would think it is. It's the message that's actually displayed on the screen.
If nothing is entered into the textbox, when focus to the textbox is lost, it will fire (whether tabbing out of the textbox, or submitting the form).
Thursday, April 10, 2008
Validation Controls in ASP.NET
Labels:
ASP.NET,
ASP.NET 2.0
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment