1. Use
OnCheckedChanged
event (the name of the function to be executed when the Checked property has changed) of Radio Button.
2. Call the same function on that event for all Radio Buttons.
3. In that event, check which radio button is clicked.
4. Show in label about that Radio Button.
Refer -
How to use OnCheckedChanged event in RadioButton[
^], which gives similar type of requirement.
So, in your aspx, Radio Buttons will look like below.
<asp:RadioButton
ID="RadioButton1"
runat="server"
Text="RadioButton1"
OnCheckedChanged="RadioButton_CheckedChanged"
AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton
ID="RadioButton2"
runat="server"
Text="RadioButton2"
OnCheckedChanged="RadioButton_CheckedChanged"
AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton
ID="RadioButton3"
runat="server"
Text="RadioButton3"
OnCheckedChanged="RadioButton_CheckedChanged"
AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton
ID="RadioButton4"
runat="server"
Text="RadioButton4"
OnCheckedChanged="RadioButton_CheckedChanged"
AutoPostBack="true">
</asp:RadioButton>
So, as you can see the function
"RadioButton_CheckedChanged"
is called for all Radio Buttons'
OnCheckedChanged
Event.
Now in cs page, do like below.
protected void RadioButton_CheckedChanged(object sender, System.EventArgs e)
{
if (RadioButton1.Checked)
{
Label1.Text = "You choose: " + RadioButton1.Text;
}
if (RadioButton2.Checked)
{
Label1.Text = "You choose: " + RadioButton2.Text;
}
if (RadioButton3.Checked)
{
Label1.Text = "You choose: " + RadioButton3.Text;
}
if (RadioButton4.Checked)
{
Label1.Text = "You choose: " + RadioButton4.Text;
}
}