Strange behavior of RadioButtonList inside a Repeater

R

ri_davila

I made a Web User Control "QuestionUserControl" that contains a RadioButtonList and a TextBox. On my web form I use that control inside a Repeater.

(i changed the tags so the code is shown)

[ASP:REPEATER id="QuestionRepeater" runat="server"]
[ITEMTEMPLATE]
[UC1:QUESTIONUSERCONTROL id="quc" runat="server"][/UC1:QUESTIONUSERCONTROL]
[/ITEMTEMPLATE]
[/ASP:REPEATER]

The repeater is then bound to a data source that contains records in the following format: QuestionId INT, QuestionType BYTE (1 = choice, 2 = text)

On the Repeater's DataBound event I call a public method of the QuestionUserControl passing the DataRow that contains QuestionId and QuestionType.


private void QuestionRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
( (Cuestionario.QuestionUserControl)e.Item.FindControl("quc") ).ContructQuestion((DataRowView)e.Item.DataItem, this.m_Language);
}


The Public Method in the QuestionUserControl then shows or hides the RadioButtonList or the TextBox depending on the QuestionType. If QuestionType was "choices" the QuestionUserControl then uses QuestionId to retreive a list of choices from the database and binds that to the RadioButtonList.

After the user posts back I gather the values from the multiple QuestionUserControls created by the repeater in the QuestionUserControl_UnLoad event.

Now the problem.

I can gather all the values posted except for the very first RadioButtonList that gets created. Example:

Repeater's Datasource:

The repeater creates 5 QuestionUserControls.

QuestionId QuestionType
1 -------- 1
2 -------- 1
3 -------- 2
4 -------- 1
5 -------- 2

This creates 5 QuestionUserControls.
The QuestionUserControls that receive a QuestionType == 1, retreive a list of choices and binds them to the RadioButtonList and hide the TextBox.
The QuestionUserControls that receive a QuestionType == 2, simply hide the RadioButtonList and shows the TextBox.

When the user submits the form, the QuestionUserControl_UnLoad event gets fired 5 times, one for each QuestionUserControl created by the repeater. Inside each QuestionUserControl_UnLoad event I have access to the RadioButtonList and the TextBox contained on that particular QuestionUserControl created by the repeater, so I can gather the values of each QuestionUserControl separately.

Once again, inside each QuestionUserControl_UnLoad I can get the values w/o a problem except for the very first QuestionUserControl that has a RadioButtonList.

I changed the order of the questions to put a QuestionUserControl that gets QuestionType == 2 (text) at the top and it had no problems. So it really doesn't matter the order of the QuestionUserControls that the Repeater creates.

The very first QuestionUserControl that contains a RadioButtonList acts as if the RadioButtonList has just been initialized with properties like:

SelectedIndex = -1
SelectedValue = ""


Sorry for such a long post. I just wanted to make sure you have all the info to help me. This is really driving me crazy .

TIA
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top