Tuesday, September 28, 2010

RadioButton Server Control

RadioButton Server Control

The RadioButton Server Control functionality is similar to the CheckBox control. But the design goes differently. RadioButton symbol is a round button, where as CheckBox symbol is a square box.

RadioButton control on a page takes the following construction:

Figure goes here…..

.aspx

<asp:RadioButton ID="rdlMale" Text="Male" GroupName="Gender" runat="server" />
<asp:RadioButton ID="rdlFemale" Text="Female" GroupName="Gender" runat="server" />

The user can select Male or Female at once. He cant select both as CheckBox does that. I used GroupName property to do this way.


Coming to the Event handler.


Figure Goes Here……

.aspx

<asp:RadioButton ID="rdlMale" AutoPostBack="true" Text="Male" GroupName="Gender"
runat="server" OnCheckedChanged="rdlMale_CheckedChanged" />
<asp:RadioButton ID="rdlFemale" AutoPostBack="true" Text="Female" OnCheckedChanged="rdlMale_CheckedChanged"
GroupName="Gender" runat="server" />
<br />
<asp:Label ID="lblOutput" runat="server" ></asp:Label>

.cs

protected void rdlMale_CheckedChanged(object sender, EventArgs e)
{
if (rdlMale.Checked)
lblOutput.Text = "Welcome Mr.";
else
lblOutput.Text = "Welcome Mrs.";
}

0 comments:

Post a Comment

Related Posts with Thumbnails