cancel
 

 

Job type :

Zip Code :

community forums

Featuring over 100 topics of interest to DoItYourselfers.

How to Specify Required Fields for the Name Control

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Video Transcript

So I think we are ready to go here, let us think about the name textbox. The name textbox is going to have a required field validator and I am going to drive the required field validator onto the right-hand column of the HTML table. And this is quite a common arrangement, you set up an HTML table by the first column contains labels and the middle column contains textboxes and the right-hand side column contains validators. And the validators will display error messages at this point.

So let us select the required field validator, and let us have a look at the properties that we need to set. Well, it is just like every control, probably the first thing you want to do is to set the ID. So I am going to adopt the name in convention here that the validator control will be called Name Required Field Validator. So the ID for this validator is Name Required Field Validator because it is the required field validator for the name textbox.

You can also set some aesthetic properties if you want. So for example, you can set the background color, and that would govern the background color for the error messages that get displayed here. One thing you have got to set is the control to validate. Obviously, the validator needs to know which control it is associated with and each validator validates one control. So if you click the dropdown here, you can choose which of these various controls you want to validate name textbox.

So our validator will be validating the name textbox. Let us look at some of the other properties we casn set. There is a display property. The display property can be static or dynamic, I will choose dynamic and then later on, we will see what happens if you choose static.

The next property enables client script. You would probably want to set this to true. This enables ASP.NET to inject client site to Java script into the HTML page that returns to the browser, so that the HTML page can perform client site validation, as well as service site validation. So the benefits of client side validation are generally a better experience for the user because as soon as they enter an invalid value, the client site browser immediately flags up the error without requiring a postback to the server. So the user gets the error information more quickly and it plays less network load on our network. So generally speaking, you will want to enable client script but you could disable it if you wanted to. And one thing to bear in mind as well, some users disable Java script in their browsers, so this is only an potion and addition to service site validation.

Okay, if we move on, we have a property called error message. Now the error message will be used by the validation summary control if it displays error information at the bottom of the page. So let us choose a simple message here such as name required. And also another property you might want to set focus on error, so that if the user does enter some invalid text or the validation fails, then it will return the input cursor to the control that has been validated, so the user can immediately correct their error.

Now the text property, is the text that will actually appear at the point where you put the validator control. So for now, we will just leave that as the same as the error message, name required.

There is another property called validation group, I am going to explain how that works at the end of this lesson, so we just skip over that for now.

So let us run the application Control F5 and see if the name validation work so far. So I will type in a value to the name, Andy and then I will cursor into the next text field. So it clearly thinks that that is valid. If I delete it and then attempt to move into different text field, at this point, we have performed validation. This validation has occurred at the client, there was no postback to the server involved but clearly it indicates that we have to enter a name in this field so that is very helpful.
So I think we are ready to go here, let us think about the name textbox. The name textbox is going to have a required field validator and I am going to drive the required field validator onto the right-hand column of the HTML table. And this is quite a... click to read more


Painting Stylish Wall Borders

sponsored articles of the day

diy centers

Research and explore a wealth of wisdom on these topics