tags:

views:

32

answers:

3

Hello,

I am trying to add a radio button click event at runtime.

Radiobutton button = new RadioButton();
button.GroupName = "buttonGroup";
button.OnCheckedChanged = "buttonGroup_OnCheckedChanged"; //I can't do this?

I know I can do this from the markup, but when I try to do this from the code behine, I cant find OnCheckedChanged.

Thanks for your help.

A: 

button.CheckedChanged += buttonGroup_OnCheckedChanged;

I believe that is what you want.

Then you would obviously define buttonGroup_OnCheckedChanged and so on.

Liggi
Hi, thanks you all for help. But, do you know why the event is not firing? I have event handler protected void buttonGroup_CheckedChanged(object sender, System.EventArgs e) {}
tony
Try setting AutoPostBack="true".
Liggi
+1  A: 
button.CheckedChanged  += new EventHandler(buttonGroup_OnCheckedChanged);
p.campbell
What would be the difference between my answer and yours? I'm curious as to whether I should be doing it differently.
Liggi
A: 

The handler should be created on page Init, the other answers are otherwise correct.

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        button.CheckedChanged += new EventHandler(buttonGroup_OnCheckedChanged);
    }
jarrett