Tuesday, 26 July 2011

ASP.NET Validation Part 6 Validation Summary


This tutorial is the sixth part of the ASP.NET Validation tutorial series. This tutorial will demonstrate how to use the validation summary with ASP.NET 4.0.

What is the ValidationSummary?
The validation summary is an ASP.NET control that allows you to easily display validation error messages. It works by taking all of the validation error messages from an invalid page and displays them in a single location. The validation summary is used on pages that contain validators to simplify and organize error messages for the user.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Using the ValidationSummary
To demonstrate the use of a validation summary, we will need to create a simple web page with a few validators on it. 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 'TextBox1 is required.'
  10. Set the ControlToValidate property to 'TextBox1'.
  11. Set the Text property to '*'.
  12. Add a break line.
  13. Drag and drop a textbox onto the web form.
  14. Drag and drop a requiredfieldvalidator onto the web form.
  15. Change the ErrorMessage property to 'TextBox2 is required.'
  16. Set the ControlToValidate property to 'TextBox2'.
  17. Set the Text property to '*'.
  18. Add a break line.
  19. Drag and drop a button onto the web form.
  20. Add a break line.
  21. Drag and drop a validationsummary onto the web form.
This has created a simple form with two text boxes that are validated as required fields and a button to cause validation. By default, the validation summary will pick up on the error messages that need to be displayed on the page, without us having to specify which validator's error messages to display. However, you can pick and choose what validator's you want to be applied to the validation summary by making them all a part of a validation group. To do this, you would need to change the ValidationGroup property on each of the controls you wanted to associate with each other. Furthermore, you can also choose a display mode to format the display of the validation summary. The validation summary offers three different display modes, BulletList, List, and SingleParagraph. Also, the validation summary allows you to choose whether you want to display the errors on the web page or a message box via the ShowSummary and ShowMessageBox properties.

We stand behind Server Intellect and their support team. They offer dedicated servers , and they are now offering cloud hosting

Testing
To test this out, simply load up the page and click the button. Notice that the error messages are displayed at the bottom in the validation summary. Also, notice that the text property of our required field validators is now displayed next to the text boxes. This is because a validation summary is displaying the errors. If there were no validation summary on the page, the error message would be displayed next to the text boxes instead.

No comments:

Post a Comment