I wonder if someone can point out where I'm going wrong with this code.

My aim is to control the visibility of an UpdatePanel with a CheckBox. The CheckBox is located on the same form, but not adjacent to the UpdatePanel. ScriptManager is present, but when browsing, checking the CheckBox doesn't make the panel visible. See below snippets, the current method used is AutoPostBack, but I'm sure this isn't the most effective way of updating the panel.

Here is the CheckBox code:

     <!-- more options checkboxes -->
<asp:CheckBox ID="HousekeepingCheckBox" runat="server" AutoPostBack="true" /> Housekeeping<br />

Here is the UpdatePanel:

<asp:UpdatePanel ID="HousekeepingUpdatePanel" runat="server" Visible="False" UpdateMode="Conditional">
            <ContentTemplate>
                <p>
                    Housekeeping Requirements:
                </p>
                <p>
                    <asp:CheckBox ID="HKHandTowelsCheckBox" runat="server" Text="Hand towels and toilet paper are restocked before the event begins" /><br />
                    <asp:CheckBox ID="HkWasteBinsCheckBox" runat="server" Text="There are adequate waste bins for the disposal of hand towels" /><br />
                    <asp:CheckBox ID="HKRoomsCleanedAfterCheckBox" runat="server" Text="The rooms used are cleaned after the event" /><br />
            </ContentTemplate>
</asp:UpdatePanel>

The code behind currently used to enable the UpdatePanel is:

Protected Sub HousekeepingCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles HousekeepingCheckBox.CheckedChanged
     If HousekeepingCheckBox.Checked = True Then
        HousekeepingUpdatePanel.Visible = True
     Else
        HousekeepingUpdatePanel.Visible = False
     End If
End Sub

I've looked at Triggers but not sure this is the solution and I haven't had any joy without AutoPostBack.

Can anyone please advise on the correct way?

Many thanks

Recommended Answers

All 3 Replies

If you do not mind having javascript in your page you can do this without posting back. Otherwise, by doing this with asp it is done on server side and will require the page to refresh everytime you click the checkbox.

Thanks for your response, but is this really the case?

I was under the impression UpdatePanels (and their view state) could be refreshed independent of the page.
I've followed tutorials where this has worked, but for some reason it doesn't on my page. Not sure if location of the CheckBoxes matter?

im sorry i totally missed the part where you were using an UpdatePanel, I am unfamiliar with these controls but heres a paper that seems rather complete and could help you,

Again sorry for missing some essential information from your question, i was completly wrong in my first post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.