RadioButton CheckChanged event not firing on first selection
am 23.04.2008 16:05:44 von Emma MiddlebrookHi there,
I'm having problems in an ASP.NET page that is dynamically creating
and displaying radio buttons. I have setup a checkchanged event and
specified AutoPostBack to true.
When the page loads none of the radio buttons are checked by default.
When the user checks the first one, the page refreshes but the
checkchanged event never triggers. If you then select a different
radio button, the postback occurs but the event also triggers.
Can anyone suggest something that might be stopping the first event to
be sent?
The display code creating the controls is:
void DisplayQuestion(Question question, bool checkRadio)
{
Label lblTitle = new Label();
lblTitle.ID = "lblQuestionOneTitle" + uniqueId;
lblTitle.Text = string.Format("{0}.{1}. ", questionSequence,
questionSecondSequence);
Label lblQuestionText = new Label();
lblQuestionText.ID = "lblQuestionText" + uniqueId;
lblQuestionText.Text = question.QuestionText;
RadioButton rbNo = new RadioButton();
rbNo.Checked = checkRadio;
rbNo.ID = "rbNo" + uniqueId;
rbNo.GroupName = "QuestionAnswer" + uniqueId;
rbNo.Text = "No";
rbNo.CheckedChanged += QuestionNoAnswered;
rbNo.AutoPostBack = true;
RadioButton rbYes = new RadioButton();
rbYes.Checked = false;
rbYes.ID = "rbYes" + uniqueId;
rbYes.GroupName = "QuestionAnswer" + uniqueId;
rbYes.Text = "Yes";
rbYes.CheckedChanged += QuestionAnswered;
rbYes.AutoPostBack = true;
RadioButtonList rbl = new RadioButtonList();
rbl.Controls.Add(rbNo);
rbl.Controls.Add(rbYes);
upQuestionBlock.ContentTemplateContainer.Controls.Add(lblTit le);
upQuestionBlock.ContentTemplateContainer.Controls.Add(lblQue stionText);
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbl);
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbYes) ;
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbNo);
}
Thanks,
Emma