Validation Controls / Validation Summary
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Now in this video I want to talk about a Validation Summary Control and this thing solves a problem that we are slowly building here through these examples of these Validation Controls. Notice, you know, we have applied Validation Controls - we've put a Required Validator here against the Last Name field, we've put a Validator about a valid Social Security number and that is a Regular Expression Validator and then we've put a Range Validator on the Age field. Now also keep in mind that, for example, if I don't input a Social Security number I won't get an error and so I will have to also make that a Required Field, so I'll put a RequiredFieldValidator out there and point to it as well. Now you can tell that this is going to start to get kind of ugly at some point and it can also be a bit confusing to the user if I have a lot of fields and stuff start showing up around them. One of the cool things you can do is and you have to watch your page design and make sure these show up on a page in a visible location for when the user clicks on the Send button, but I can grab a ValidationSummary and that's what I'm going to do. Left-click, I'll drag it onto the page and I'm going to drop it in that cell right under the button right there. And, what I can do now is have all my error messages show up in one place. Now, to do that I need to make sure first of all that my error messages are a little more explanatory, that they point back up to the appropriate place up here in their description and I want to take things like these little arrows out. Also, I need to turn it off up here because I don't want it to appear up here anymore so let's go through our Controls and set these things. On my RequiredFieldValidator I'll click on it and you'll see I get the RequiredFieldValidator here. I'm going to come down on Display, I'm going to change that to None. I don't want it showing up here. And then on my Error Message, I'm going to change it. I'll take those arrows off and then I will say Last Name is a required field. Or, really what I should say is: You must enter a Last Name. Then on the Social Security number I will turn that one off and I will put: This is not a valid SSN. Then on the Age I will turn that one to None. I've got that one on None, didn't I? Yes, I did. Then on the Age the RangeValidator is set to Display to None. There we go. And, let me make this a little easier to read. All I've done is cleaned up my error messages a little bit and so now I've set them all to None. I've dropped a RangeValidator on. On my ValidationSummary, dropped a ValidationSummary on. Really all I have to do at that point, there's not a lot to set on this thing at this point. I will just simply run this, run it without debugging and now if I cause a problem - let's put a valid Social Security number in and let's put a valid Age in and notice now when I click the button I'm going to violate this one. It pops up down here and says, hey, wait a minute, you must enter a Last Name and so I will enter a Last Name but I will foul up my Social Security number and it says, wait a minute, this is not a valid SSN. Now if you remember in a previous video, we worked with the SetFocus and it's taking me back to the one that is a problem. I mean once I get everybody satisfied then I'm OK and then if I put 55 here and click the Age must be between 16 and 30. Now I can also go and write some code to change the background of these things. Keep in mind on client side that'll have to be JavaScript. On the server side I can call in the Validate Method and change those things. So, you've got some more learning to do on these Validation Summaries. I wanted to introduce you to them. Go out and do some reading on them, look at some code examples. There's some really cool things you can do. But what we want to make sure that we do is that we direct our users to help them to fill out our information so that we get it the way we want it and we'll talk about security a little bit later, but this is one of the first steps in security is we want to make sure that the data that they give us, that we're writing into our databases or making branching decisions with our programs, we want to ensure that that data is coming to us correctly, in the proper format and the proper ranges that we're looking for and that it can't be toyed with to inject any kind of problems into our Web server or into our application. Anyway, that's a Validation Summary and it can really clean up all this stuff that you have going on on a busy page.
Tutorial Information
| Course: | Microsoft ASP.NET 3.5 |
| Author: | Mark Long |
| SKU: | 34102 |
| ISBN: | 1-93633412-7 |
| Release Date: | 2010-03-24 |
| Duration: | 6 hrs / 69 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 