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.
button.CheckedChanged += new EventHandler(buttonGroup_OnCheckedChanged);
button.CheckedChanged += buttonGroup_OnCheckedChanged;
I believe that is what you want.
Then you would obviously define buttonGroup_OnCheckedChanged and so on.
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);
}
精彩评论