Strange behavior of RadioButtonList inside a Repeater

Discussion in 'ASP .Net Web Controls' started by ri_davila@yahoo.com, May 9, 2006.

  1. Guest

    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
    , May 9, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi
    Replies:
    2
    Views:
    4,417
    jagdish
    Aug 18, 2006
  2. Replies:
    1
    Views:
    7,011
    Karl Seguin
    Aug 10, 2005
  3. uncensored
    Replies:
    0
    Views:
    798
    uncensored
    Oct 25, 2006
  4. robk

    RadioButtonList inside Repeater

    robk, Jul 7, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    256
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    194
    Microsoft
    Aug 21, 2006
Loading...

Share This Page