Work With Web Controls

Extra

You can use the RadioButtonList Web server control for working with multilple RadioButton Web server controls.

Example:

<FORM RUNAT="Server">

<ASP:RADIOBUTTONLIST ID="radiobuttonlistSuggestions" RUNAT="Server">

<ASP:LISTITEM>Fewer Goals</ASP:LISTITEM>

<ASP:LISTITEM>More Goals</ASP:LISTITEM>

<ASP:LISTITEM>Same Number of Goals</ASP:LISTITEM>

</ASP:RADIOBUTTONLIST>

<INPUT TYPE="Submit" VALUE="Submit"

OnServerClick="SubmitBtn_Click"

RUNAT="Server">

<ASP:LABEL ID="labelMessage" RUNAT="Server"/> </FORM>

By using this RadioButtonList Web server control, you can use the Selectedlndex property to find out which radio button was selected.

Example:

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

void SubmitBtn_Click(object Source, EventArgs e) {

(radiobuttonlistSuggestions.Selectedlndex > -1) {

labelMessage.Text = "You suggested " + radiobuttonlistSuggestions.SelectedItem.Text;

'-Q Create a function called SubmitBtn_Click to check the suggestion selected.

I Add an if statement to check whether the control was checked and send 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 first radio button.

Click the Subm it button.

-■ The suggestion echoes back.

Was this article helpful?

0 0

Post a comment