[英]RadioButton's CheckedChanged disappears after refresh
I have a ASP.Net Page with a lot of dynamic generated controls at runtime. 我有一个ASP.Net页面,在运行时有很多动态生成的控件。 Each control is bound to a "Change Event".
每个控件都绑定到一个“更改事件”。 Everything works great except RadioButtons with the CheckedChanged event.
除了带有CheckedChanged事件的RadioButtons之外,其他所有功能都很好。
First time i visit the page all works fine. 第一次访问该页面时,一切正常。 But the second time some RadioButtons have lost their CheckedChanged event.
但是第二次某些RadioButtons丢失了CheckedChanged事件。
Generated HTML Code on first page visit: 在首页访问时生成的HTML代码:
<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): 第二次访问后(第二个RadioButton中的onclick事件丢失):
<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: 控件被添加到Page_Load事件中:
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: Render()方法中的代码:
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. 似乎是AjaxToolKit中的错误。 Look at this:
看这个:
ASP.NET Radio button checked changed event not firing for first radio button ASP.NET单选按钮检查的更改事件未触发第一个单选按钮
Worked for me. 为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.