views:

11

answers:

3

I have a webform containing a user control. On that user control is a set of radio buttons. When the radio button is changed, a panel and a text box is shown or hidden depending on which radio button was selected.

I can give you an example that works correctly:

testcontrol.aspx:

<asp:RadioButtonList ID="ChoicesRadioButtonList" AutoPostBack="true" OnSelectedIndexChanged="ChoicesRadioButtonList_SelectedIndexChanged" runat="server">
    <asp:ListItem Text="Show 1"></asp:ListItem>
    <asp:ListItem Text="Show 2"></asp:ListItem>
</asp:RadioButtonList>
<asp:Panel id="Panel1" CssClass="panel1" runat="server"></asp:Panel>
<asp:Panel id="Panel2" CssClass="panel2" runat="server"></asp:Panel>

testcontrol.aspx.cs:

protected void ChoicesRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
    RadioButtonList bob = (RadioButtonList)sender;
    switch (bob.SelectedValue)
    {
        case "Show 1":
            Panel1.Visible = true;
            Panel2.Visible = false;
            break;
        case "Show 2":
            Panel1.Visible = false;
            Panel2.Visible = true;
            break;
    }
}

As I mentioned, in a test form this works properly. Panel1 and Panel2 are displayed correctly based on which radio button is selected.

I have another web page and user control with a number of other fields. When this code is on that page, I can step through the code behind for the ChoicesRadioButtonList_SelectedIndexChanged event, but nothing happens.

I am at a loss for next steps to debug this (short of rebuilding the entire page from scratch). Can anyone offer any suggestions on where to look?

A: 

Have you tried using an asp:MultiView instead of asp:Panel?

Then instead of switching the visibility of multiple panels, you just need to use SetActiveView(view) to show the required view.

Jaymz
A: 

Can you write the same code at PreRender event? Maybe something is changing the visiblity back to the default state and you are overlooking it.

sh_kamalh
A: 

I went through and started commenting out sections of code. Turns out a CalendarExtender on the page was causing the problem. It was throwing javascript errors that prevented the page from rendering corretly.

y0mbo