RadioButton CheckChanged event not firing on first selection

E

Emma Middlebrook

Hi 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(lblTitle);

upQuestionBlock.ContentTemplateContainer.Controls.Add(lblQuestionText);
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbl);
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbYes);
upQuestionBlock.ContentTemplateContainer.Controls.Add(rbNo);
}

Thanks,

Emma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top