title: Hidden Control value is not correct when read in code behind
body: <p>I have a Hidden Control in a nested gridview to determine if it is expanded or not. I set the value in the javascript function.  It is being set correctly because of alerts that I have set.  In the RowDataBound method, I want to read the Hidden control to determine if I should expand the grid or not.  When I read the value in the RowDataBound method, it is always '0'.
  My markup is huge so this is only the nested grid, UpdatePanel and hiddencontrol association:</p>
  
  <pre><code>    &lt;asp:UpdatePanel ID="updatePnlNestedGrid" runat="server" UpdateMode="Conditional"&gt;
  &lt;ContentTemplate&gt;
  &lt;div id="div&lt;%# Eval("GroupID") %&gt;" style="display:none"&gt;                      
  &lt;asp:GridView ID="GroupMemberGridView" runat="server" AutoGenerateColumns="false" OnRowDeleting="GroupMemberGridView_RowDeleting" 
   OnRowCommand="GroupMemberGridView_RowCommand" CssClass="grid" ShowFooter="true" AllowPaging="true" PageSize="5"
    onpageindexchanging="GroupMemberGridView_PageIndexChanging" onpageindexchanged="GroupMemberGridView_PageIndexChanged"&gt;
  &lt;Columns&gt;
      &lt;asp:TemplateField HeaderText="MemberID"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="mggvLblMemberID" runat="server" Text='&lt;%# Bind("MemberID") %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;asp:TemplateField HeaderText="Member Name" ItemStyle-Wrap="false"&gt; 
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="mggvLblMemberName" runat="server" Text='&lt;%# Bind("MemberName") %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;               
          &lt;FooterTemplate&gt;
              &lt;asp:DropDownList ID="mggvDDLMemberName" runat="server" 
                 class="chosen-single" data-placeholder="Choose member…"&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:RequiredFieldValidator ID="ReqValueDDLMemberInsert" runat="server" InitialValue="0" 
                      ControlToValidate="mggvDDLMemberName" 
                      ErrorMessage="Selection required." CssClass="message-error-dropdown"&gt;
              &lt;/asp:RequiredFieldValidator&gt;
          &lt;/FooterTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;asp:TemplateField HeaderText="Active Device(s)"&gt;                   
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="mggvLblActiveDevice" runat="server" Text='&lt;%# (Boolean.Parse(Eval("ActiveDevice").ToString())) ? "Yes" : "No" %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;                   
      &lt;/asp:TemplateField&gt;
      &lt;asp:TemplateField HeaderText="Action" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Button ID="mggvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete" 
                  Text="Delete" CssClass="gridActionbutton"  OnClientClick="return confirm('Are you sure you want to delete this Group Member?')" &gt;
              &lt;/asp:Button&gt;
          &lt;/ItemTemplate&gt;                                     
          &lt;FooterTemplate&gt;
              &lt;asp:Button ID="mggvAddButton" runat="server" CommandName="Add" Text="Add Member" Width="90%" 
                  CssClass="gridActionbutton"/&gt; 
          &lt;/FooterTemplate&gt;
      &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;/div&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;      
  &lt;asp:HiddenField ID="mggvIsExpanded" runat="server" ClientIDMode="Static" Value="0" /&gt;    
  </code></pre>
  
  <p>This is the javascript function that expands/collapses the grid and sets the hidden value:</p>
  
  <pre><code> function DivExpandCollapse(groupID) {    
      var div = document.getElementById(groupID);
      var img = document.getElementById('img' + groupID);
      //alert shows correct hidden value
       alert($(div).parent().siblings("input:hidden[id$='mggvIsExpanded']").val());
      if (div.style.display == "none") {               
          div.style.display = "inline";
          img.src = "Images/minus.png";
          $(div).parent().siblings("input:hidden[id$='mggvIsExpanded']").val("1");   
          $("#" + div.getAttribute('id') + ".chosen-single").chosen("destroy");
          $("#" + div.getAttribute('id') + ".chosen-single").chosen({
              search_contains: true,
              width: "100%",
              placeholder_text_single: "Choose member…",
              no_results_text: "Sorry, no match!"
          });         
      }
      else {
          div.style.display = "none";
          img.src = "Images/plus.png";
          $(div).parent().siblings("input:hidden[id$='mggvIsExpanded']").val("0");
      }
  }
  </code></pre>
  
  <p>This is the code behind event.  I am only showing the hidden value code.:</p>
  
  <pre><code>protected void UserGroupGridView_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        int tiGroupID = Convert.ToInt32(UserGroupGridView.DataKeys[e.Row.RowIndex].Value.ToString());
        GridView tgvGroupMember = (GridView)e.Row.FindControl("GroupMemberGridView");
          HiddenField hiddenExpand = (HiddenField)tgvGroupMember.Parent.FindControl("mggvIsExpanded");
          //This value is always "0" - the initial value
          String hiddenValue = hiddenExpand.Value.ToString(); 
     }
   }
  </code></pre>
  
  <p>Even though the hidden value is set in the javascript.  The value is always zero in the code behind which is the initial value.</p>
  
  <p>Why is the hidden value never showing as "1" in the RowDataBound event when the grid is expanded?</p>
  
  <p><strong>UPDATE</strong>
  I put the asp:HiddenField inside the ContentTemplate which is inside the UpdatePanel.  But it still is not reading the hidden value correctly.</p>