开发者

Adding radio button event handler at runtime

开发者 https://www.devze.com 2023-01-15 11:58 出处:网络
I 开发者_开发百科am trying to add a radio button click event at runtime. Radiobutton button = new RadioButton();

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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消