Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Validation - ASP.NET Validation Part 1 Required Field Validator
ASP.NET Validation Part 1 Required Field Validator

ASP.Net 4.0 Tutorials V4
Server Intellect Cloud Hosting

ASP.NET Validation Tutorial

This tutorial is the first part of the ASP.NET Validation tutorial series. This tutorial will demonstrate how to use the required field validator for server side validation using ASP.NET 4.0.

What is the RequiredFieldValidator?
The required field validator is an ASP.NET control that allows us to validate that a field has data before continuing. The required field validator uses server side validation to check a specified control for data. This validator is both extremely simple to use and powerful. An example of where you would use this would be for something like a user registration, in which you have a text box for the user to enter a username that is required to go on.

We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

Using the RequiredFieldValidator
To demonstrate this control, we will create a simple web site in which we will have a text box and button. The button will initiate validation on the text box and our required field validator will determine if an error needs to be displayed or if we can move on. To do this, create a new ASP.NET Empty Web Site and:
  1. Right click the project in your solution explorer.
  2. Select add new item...
  3. Select a web form.
  4. Name it 'Default.aspx'.
  5. Click add.
  6. Open Default.aspx up to design mode.
  7. Drag and drop a textbox onto the web form.
  8. Drag and drop a requiredfieldvalidator onto the web form.
  9. Change the ErrorMessage property to 'Text box is required!'.
  10. Change the ControlToValidate property to 'TextBox1'.
  11. Add a break line.
  12. Drag and drop a button onto the web form.
What this has done, is associated the text box we added with the required field validator. In this case, it should display an error message if the text box is empty and the button is clicked.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Testing
To test this out, simply load up the web site and click the button. Notice that the error message we specified earlier is displayed. The text box did not pass validation because it is required to contain some sort of data. Go ahead and add some text to the text box and then click the button, notice the error message was not displayed meaning it passed validation.
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!



 
  Developer Resources







Server Intellect Rocks