Work With Web Controls

You can also validate other controls. For example, you can validate a drop-down list box. To do this, you need to set the INITIALVALUE attribute for the REQUIREDFIELDVALIDATOR element equal to the value that associates that the user has not selected an option.

TYPE THIS:

<FONT FACE ="Verdana">

<H3>Welcome to mylifetimegoals.com</H3> What suggestions do you have for improving our site? <FORM RUNAT="Server">

<ASP:DROPDOWNLIST ID="dropdownlistSuggestions" RUNAT="Server"> <ASP:LISTITEM>Choose</ASP:LISTITEM> <ASP:LISTITEM>Fewer Goals</ASP:LISTITEM> <ASP:LISTITEM>More Goals</ASP:LISTITEM> <ASP:LISTITEM>Same Number of Goals</ASP:LISTITEM> </ASP:DROPDOWNLIST>

<P/><ASP:BUTTON TEXT=nSubmit" RUNAT="Server"/><P/> <ASP:REQUIREDFIELDVALIDATOR ID="requiredfieldvalidatorInputNane" CONTROLTOVALIDATE="dropdownlistSuggestions" TEXT="You must select a suggestion! </FORM> </FONT> </BODY> </HTML>

INITIALVALUE=nChoose" RUNAT="Server"/>

RESULT:

A page with a dropdown list appears that requires a selection to be made before submitting the page.

Within the RequiredFieldValidator control, set the validation message by specifying the TEXT attribute.

, Save the file and request it from the Web server.

Note: See pages 20 to 25 for instructions on saving a file to the Web server and then requesting the file using the IIS Admin.

Note: Do not fill in the login name box.

A validation message appears.

Was this article helpful?

0 0

Post a comment