Work With Web Controls

Extr

You can use the CheckBoxList Web server

To respond to a Web form that contains multiple

control for working with multiple check boxes.

check boxes, you can use the event handler code.

Example:

Example:

<FORM RUNAT="Server">

<SCRIPT LANGUAGE="C#" RUNAT="Server">

<P/>

void SubmitBtn_Click(object Source,

<ASP:CHECKBOXLIST ID="checkboxlistSuggestions" RUNAT="Server">

String sMessage = "";

<ASP:LISTITEM>Have more goals to choose from.</ASP:LISTITEM>

checkboxlistSuggestions.Items.Count; i++) {

<ASP:LISTITEM>Have more goal categories.</ASP:LISTITEM>

if ( checkboxlistSuggestions. Items[ i j.Selected ) {

<ASP:LISTITEM>Make the goal setting wizard easier.</ASP:LISTITEM>

sMessage = sMessage + checkboxlistSuggestions.Items[i].Text;

</ASP:CHECKBOXLIST>

sMessage = sMessage + "<BR />";

<P/>

}

<ASP:BUTTON TEXT="Submit"

OnClick="SubmitBtn_Click" RUNAT="Server"/>

<ASP:LABEL ID="labelMessage" RUNAT="SERVER"/>

if (sMessage != "") {

labelMessage.Text ="Your suggestions" + "are...<BR />" + sMessage;

</FORM>

}

else {

labelMessage.Text = "You have no suggestions."; }

</SCRIPT>

t

—Q Create a function called SubmitBtn_Click to check the password.

I Add an if statement to check whether the control was checked and set the appropriate message.

, 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.

I Click to select the check box.

Click the Subm it button.

-■ The suggestion echoes back.

QUEST A SELECTION FROM A GROUP

You can use radio buttons to have a user select a single option from a group of choices. The RadioButton control functions similarly to the

HTMLRadioButton server control.

To employ the RadioButton Web server control on your server form, you must first declare a RadioButton Web server control with the <ASP:RadioButton RUNAT="Server"> tag. Then, you must give each radio control button that you want a unique id attribute. To associate a group of radio buttons, set the groupname attribute to be the same for all controls in the group. You can also specify which of the radio buttons is checked when the user requests the page. You can do this by setting the checked attribute for the radio button to True.

Radio buttons are typically implemented in groups of two or more, where you force the user to choose one option out of a list of options. To conveniently work with a group of radio control buttons, you can use the

RadioButtonList Web server control.

In this example, you are asking a question that requires only one answer from a group of answers. To do this, you create a form with multiple RadioButton Web server controls in the same group. When the user submits the form, the Checked property of the controls formats a message.

REQUEST A SELECTION FROM A GROUP

REQUEST A SELECTION FROM A GROUP

D Open the

GenericTemplate.aspx template from the Code Templates directory.

Q Add a server form to the page.

-0 Add a Button Web control that calls the SubmitBtn_Click for the onClick event.

^0 Add a Label control for the message.

Q Add a RadioButton

Web server control for each of the radio button options and set the GROUPNAME attribute for the controls to be the same so they are in a group.

D Open the

GenericTemplate.aspx template from the Code Templates directory.

Q Add a server form to the page.

-0 Add a Button Web control that calls the SubmitBtn_Click for the onClick event.

^0 Add a Label control for the message.

Q Add a RadioButton

Web server control for each of the radio button options and set the GROUPNAME attribute for the controls to be the same so they are in a group.

Was this article helpful?

0 0

Post a comment