简体   繁体   中英

C# Dynamic RadioButton in Update Panel is not firing on first click?

I have a number of radio buttons created dynamically inside a loop and added to a div inside update panel. On each postback request triggered by checked change event, I recreate the radio buttons in my page_init method. My problem is the radio button I selected is not checked and the checked changed event is not firing on first click. But on subsequent clicks, it works normally and the checked changed event is fired. Only the first click is not firing. What could be the issue?

Simple dynamic radio button.

RadioButton btn2 = new RadioButton();
btn2.Text = "TEST";
btn2.CheckedChanged += Btn2_CheckedChanged; ;
btn2.AutoPostBack = true;
pricetbldiv.Controls.Add(btn2);

private void Btn2_CheckedChanged(object sender, EventArgs e)
{
     RadioButton btn = (RadioButton)sender;
     string text = btn.Text;
}

Try to assign group and ID

       btn2.ID = "Text";
        btn2.Text = "Text";
        btn2.GroupName = "RB";
        btn2.CheckedChanged += new EventHandler(Btn2_CheckedChanged);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM