Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
I have four radio buttons and four method.when I click a radio button appropriate method should be called and display result in label in ASP.NET(asp.net with c#.net).
 
Thanks in Advance
Posted 15-Feb-13 23:20pm
Rekhash1.5K
Comments
bandi.ramesh at 16-Feb-13 5:36am
   
radio buttons or radiobuttonlist?
Rekhash at 16-Feb-13 5:44am
   
radiobutton @bandi.ramesh
| B | A | N | D | I | at 16-Feb-13 5:46am
   
can you post your code?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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)
      {
            // Call function you want to call for "RadioButton1".
            Label1.Text = "You choose: " + RadioButton1.Text;
      }
 
      if (RadioButton2.Checked)
      {
            // Call function you want to call for "RadioButton2".
            Label1.Text = "You choose: " + RadioButton2.Text;
      }
      
      if (RadioButton3.Checked)
      {
            // Call function you want to call for "RadioButton3".
            Label1.Text = "You choose: " + RadioButton3.Text;
      }
      
      if (RadioButton4.Checked)
      {
            // Call function you want to call for "RadioButton4".
            Label1.Text = "You choose: " + RadioButton4.Text;
      }
}
  Permalink  
v9
Comments
Rekhash at 17-Feb-13 23:31pm
   
four method.when I click a radio button appropriate method should be called and display result in label @Tadit Dash
Tadit Dash at 18-Feb-13 1:11am
   
Yes, exactly...
As you can see I have commented statements in each if block saying
 
"// Call function you want to call for "RadioButton1"."
 
This is where you need to call your function for "RadioButton1".
 
So, you can call all the functions one by one in each if block and do what you want to do.
 
Got it?
Please reply.
Rekhash at 18-Feb-13 2:47am
   
Ok i got it.Thanks @Tadit Dash
Tadit Dash at 18-Feb-13 4:58am
   
Hi Rekhash,
 
Anytime. My pleasure.
 
Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...
 
Thanks,
Tadit
Tadit Dash at 18-Feb-13 6:41am
   
Hi Rekhash,
 
You are toggling between accepting and undoing accepting of this answer.
 
Please make sure you accept this answer and not doing undo again.
Please accept.
 
Thanks,
Tadit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 90
3 ProgramFOX 80
4 Sandeep Singh Shekhawat 70
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100