Simple Validator Example using RequiredFieldValidator and web controls

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 14
July 20, 2001
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Simple Validator Example

One of the coolest things about ASP.NET is using Web Controls.  These are replacements for using traditional HTML controls such as a button, textbox etc.. Have you ever had to needed to have a field needs to be filled before its submitted.  Using Web Controls has a control called <asp:RequiredFieldValidator> that if put right after the server control will ensure the field has a value to fill text box

One of the major benefits about using ASP.NET web controls is the validation route. Depending on what browser requests the page, the ASP.NET engine will render client-side javascript code automatically to validate the form on the client. If the browser isn't capable to handle the client side validation routine, the form is submitted to server causing a round trip.

This simple example just shows the concept of requiring one field to be filled in.  Some of the advanced things that also can be done is using Regular Expressions to further validate the data in the textbox, checkbox or radio button(s). 
 

<html>
<head></head>
<body>
      <form runat="server" id="form2" name="form2">
                <table border=1>
                       <tr>
                              <td>id</td>
                              <td><asp:textbox id="atid" runat="server" /> 
                               <asp:RequiredFieldValidator runat="server" id="vldid" ControlToValidate="atid" 
ErrorMessage="id is required" display="Static">This Required Field!</asp:RequiredFieldValidator></td>
                       </tr>
                       <tr>
                               <td>FavCar</td>
                               <td><asp:textbox id="atFavCar" runat="server" /></td>
                       </tr>
                       <tr>
                               <td colspan="2"><asp:button id="button1" Text="Validate Form" runat="Server" /></td>
                       </tr>
                </table>
          </form>
</body>
</html>

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials