Checkbox does not get checked/unchecked when used as control for CollapsiblePanelExtender

1.1k Views Asked by At

Has anyone else tried to use checkbox as control to collapse/expand the AJAX CollapsiblePanelExtender?

The panel collapses/expands fine when I am clicking the checkbox. But the checkbox itself won't get checked.

Did that happen to you too?

I know there's a work around this, but I can't rest until I understand why.

Here's the code just in case someone wants to see:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>    
<div class="standard"> 
    <asp:UpdatePanel ID="UpdatePanelBespokeRates" runat="server">
        <ContentTemplate>       
            <asp:CheckBox ID="checkbespoke" runat="server" AutoPostBack="False" Checked="false" Text="Click and unclick this checkbox" />
            </p>
            <asp:UpdatePanel ID="UpdatePanelBespoke" runat="server">
                <ContentTemplate>

                    <asp:CollapsiblePanelExtender ID="CollapsibleExtender2" runat="server" 
                        TargetControlID="PnlBespokeRates" CollapseControlID="checkbespoke" 
                        CollapsedSize="1" ExpandControlID="checkbespoke" SuppressPostBack="True" 
                        Enabled="True" Collapsed="True"></asp:CollapsiblePanelExtender>

                    <asp:Panel ID="PnlBespokeRates" runat="server" Visible="True" Height="300px" Width="200px" BackColor="White">
                         <p>Another Hello World text</p>   
                    </asp:Panel> 

                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="checkbespoke" EventName="CheckedChanged" />
                </Triggers>
            </asp:UpdatePanel>

        </ContentTemplate>
    </asp:UpdatePanel>
    <p>
</div>

in the Code behind it is:

protected void Page_Load(object sender, EventArgs e)
    {
        CollapsibleExtender2.ClientState = "true";
        CollapsibleExtender2.Collapsed = true;
    }
2

There are 2 best solutions below

0
Justin Harvey On

Try removing Checked="false" from the asp:CheckBox declaration. I suspect that the postback trigger may be reloading the checkbox and re-initialising it.

0
Darcy Q On

What worked was:

SuppressPostback="false" in the CollapsiblePanelExtender attribute

and

Autopostback="true" in the checkbox control

remove all manual C#

And then voila.