I have a ASP.Net Page with a lot of dynamic generated controls at runtime. Each control is bound to a "Change Event". Everything works great except RadioButtons with the CheckedChanged event.
First time i visit the page all works fine. But the second time some RadioButtons have lost their CheckedChanged event.
Generated HTML Code on first page visit:
<input id="ctl00_masterContentPlaceHolder_question467b446b749c4252a4df1839ae81ee7fYesRadioButton" type="radio" name="ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fRadioButtonGroup" value="question467b446b749c4252a4df1839ae81ee7fYesRadioButton" onclick="javascript:setTimeout('__doPostBack(\'ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fYesRadioButton\',\'\')', 0)" tabindex="1">
<input id="ctl00_masterContentPlaceHolder_question467b446b749c4252a4df1839ae81ee7fNoRadioButton" type="radio" name="ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fRadioButtonGroup" value="question467b446b749c4252a4df1839ae81ee7fNoRadioButton" onclick="javascript:setTimeout('__doPostBack(\'ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fNoRadioButton\',\'\')', 0)">
After second visit (the onclick event from the second RadioButton is lost):
<input id="ctl00_masterContentPlaceHolder_question467b446b749c4252a4df1839ae81ee7fYesRadioButton" type="radio" name="ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fRadioButtonGroup" value="question467b446b749c4252a4df1839ae81ee7fYesRadioButton" onclick="javascript:setTimeout('__doPostBack(\'ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fYesRadioButton\',\'\')', 0)" tabindex="1">
<input id="ctl00_masterContentPlaceHolder_question467b446b749c4252a4df1839ae81ee7fNoRadioButton" type="radio" name="ctl00$masterContentPlaceHolder$question467b446b749c4252a4df1839ae81ee7fRadioButtonGroup" value="question467b446b749c4252a4df1839ae81ee7fNoRadioButton" checked="checked">
Edit
Controls are added inside the Page_Load event:
System.Collections.Generic.List<CPM.Arda.Questionnaire.Base.Objects.QuestionRenderResult<System.Web.UI.Control>> questionRenderResults = _questionnaireParser.Render(questionnaireGroup, false);
foreach (CPM.Arda.Questionnaire.Base.Objects.QuestionRenderResult<System.Web.UI.Control> questionRenderResult in questionRenderResults)
questionnaireGroupControlsPanel.Controls.Add(questionRenderResult.QuestionControl);
Code inside the Render() method:
System.Web.UI.WebControls.RadioButton yesRadioButton = new System.Web.UI.WebControls.RadioButton();
yesRadioButton.ID = "question" + questionnaireGroupQuestion.Id.ToString().Replace("-", "") + "YesRadioButton";
yesRadioButton.Text = "Ja";
yesRadioButton.GroupName = "question" + questionnaireGroupQuestion.Id.ToString().Replace("-", "") + "RadioButtonGroup";
yesRadioButton.TabIndex = tabIndex;
yesRadioButton.Enabled = !_readOnly;
yesRadioButton.AutoPostBack = true;
yesRadioButton.CheckedChanged += inputControl_ValueChanged;
System.Web.UI.WebControls.RadioButton noRadioButton = new System.Web.UI.WebControls.RadioButton();
noRadioButton.ID = "question" + questionnaireGroupQuestion.Id.ToString().Replace("-", "") + "NoRadioButton";
noRadioButton.Text = "Nein";
noRadioButton.GroupName = "question" + questionnaireGroupQuestion.Id.ToString().Replace("-", "") + "RadioButtonGroup";
noRadioButton.Style.Add("margin-left", "10px");
noRadioButton.Enabled = !_readOnly;
noRadioButton.AutoPostBack = true;
noRadioButton.CheckedChanged += inputControl_ValueChanged;
Can anyone explain this?
Found a solution for my problem.
Seems to be a bug in AjaxToolKit. Look at this:
ASP.NET Radio button checked changed event not firing for first radio button
Worked for me.
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.