Tuesday, February 24, 2009

Using a RequiredFieldValidator,Computers Category

When you need to ensure that a field is filled out by people who visit your website, you do not need a lot of complex code in a variety of scripting languages. ASP.NET VB corresponds to the task !

Create the table

Let's create a sample form on which we can play, which is something that is used in real life. Create a table with four rows and two columns. Combine the cells of the first and last rows .

first thing to do, add the verbiage so we know what we are looking for. Row 1: "home page" Row 2 Column 1: "Username:" Row 3 Column 1: "Password: "

Table Full

From the toolbox, add follows: Column 2 Row 2: HTML input box textRow type = 3 Column 3: entry box type HTML passwordRow = 4: Button

There are a couple of properties to be specified in the input boxes . To include "ID" and "runat". In the input box to add user name: id = "txtUserName" runat = "server". In the Password box enter: id = "txtPassword" runat = "server ".

Rename the button" Login "and add an event OnClick events through the window, while the Design view. It can be left empty .

While the sources of light, place your cursor immediately after the closing tag input box. Add a RequiredFieldValidator to the toolbox. An opening and closing tag will be created for you, along with default information. In-between the new tags, insert an asterisk to the server as a reminder that the missing information. To emphasize the Rose, add the following tag to open :

validator ForeColor = "red "

As the validator controls nothing. To make it responsive to the input box for user name, add the following to open the tag validator :

ControlToValidate = "txtUserName "

Design View

Repeat two step txtPassword entry box. Insert the validator, add the asterisk, ForeColor to change the color red, and finally add the ControlToValidate. Be sure to change the use "txtPassword" instead of "txtUserName. If you forget both validators looks the same input box Run the VB .

web application to test. Try to leave the username blank. Once you click the button, it triggers the validator and the red star is visible. The validator does not allow the form to be submitted until the field has contents. When the requirement is fulfilled, the red asterisk go away.

This article is written by Writing Articles.


About the Author
Joe Keny - Everthing about internet.The above article can be found in my site Using a RequiredFieldValidator

.