Click here to Skip to main content
15,936,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

i am working on Windows application! i have used some dynamic radio buttons & submit. now i want verify the radio button values! i.e. wants to calculate the result on click of submit buttons.

now i have situation where i need get the click event for particular button. for example suppose i have clicked second submit button i need verify the resultant value for the same.

how can get index/Name of submit button on click event!...

it will have N number of button so how can get the exact value of submit button!

Any kind of link, suggestion and specially expert advice would be highly appreciated.

Thanks & regards
Balkrishna Raut!
Posted

Every event has a sender parameter, which hands you the control that raised the event: For a Form it is the form instance, for a radio button, it is the RadioButton instance. All you have to do is convert it to a RadioButton, and off you go:
private void myRadioButton_Click(object sender, EventArgs e)
    {
    RadioButton radio = sender as RadioButton;
    if (radio != null)
        {
        // Handle the click.
        }
    }
 
Share this answer
 
Comments
Olivier Levrey 31-Mar-11 4:33am    
My 5.
OriginalGriff is right. I would just add one thing:

All controls have a Tag member (of type object). You can use this member to add extra information to your control and get it back from your handler:

C#
private void myRadioButton_Click(object sender, EventArgs e)
{
    RadioButton radio = sender as RadioButton;
    //get the extra information associated with this control
    YourType extraInfo = (YourType)radio.Tag;
    ...
}
 
Share this answer
 
Comments
BobJanova 31-Mar-11 5:02am    
In particular, if radio buttons or check boxes represent indices in a data array, it can be convenient to put the array index (or Dictionary key or etc) in Tag.
Olivier Levrey 31-Mar-11 5:14am    
Exactly!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900