title: asp.net Panel visibility in an Update Control
body: <p>I am creating a mobile menu style function.</p>
  
  <p>An image button is clicked and it should show the menu if the menu is currently not shown, and hide it if the menu is currently shown.</p>
  
  <pre><code>&lt;div class="menuicon"&gt;
                  &lt;asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" /&gt;
                  &lt;asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" /&gt;
              &lt;/div&gt;
             &lt;div class="menulist"&gt;
                  &lt;asp:Panel ID="panMenuContainer" runat="server"&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
                              &lt;a href="UserAuthentication"&gt;Login&lt;/a&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/asp:Panel&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>the menubtn Click event:</p>
  
  <pre><code>if(hdfMenuStatus.Value == "menudown")
      {
          panMenuContainer.Visible = true;
          hdfMenuStatus.Value = "menuup";
      }
      else
      {
          panMenuContainer.Visible = false;
          hdfMenuStatus.Value = "menudown";
      }
  </code></pre>
  
  <p>This works absolutely fine, but as soon as I encase the menuicon and menulist divs in an update panel then it stops working:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
                  &lt;ContentTemplate&gt;
                      &lt;div class="menuicon"&gt;
                          &lt;asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" /&gt;
                          &lt;asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" /&gt;
                      &lt;/div&gt;
                      &lt;div class="menulist"&gt;
                          &lt;asp:Panel ID="panMenuContainer" runat="server"&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="UserAuthentication"&gt;Login&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/asp:Panel&gt;
                      &lt;/div&gt;
                  &lt;/ContentTemplate&gt;
              &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>I also put the menubtn outside the update panel with an Async Trigger but that didn't work either.</p>
  
  <pre><code>&lt;div class="menuicon"&gt;
                          &lt;asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" /&gt;
                          &lt;asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" /&gt;
                      &lt;/div&gt;
              &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
                  &lt;ContentTemplate&gt;
                      &lt;div class="menulist"&gt;
                          &lt;asp:Panel ID="panMenuContainer" runat="server"&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="UserAuthentication"&gt;Login&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/asp:Panel&gt;
                      &lt;/div&gt;
                  &lt;/ContentTemplate&gt;
                  &lt;Triggers&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="menubtn" EventName="Click" /&gt;
                  &lt;/Triggers&gt;
              &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Having a page postback just to show or hide the menu seems entirely unsatisfactory.</p>
  
  <p>Can anybody suggest what might fix this? I'm sure I've had Panel Visibility working inside an Update Panel before.</p>