title: why my asp:hiddenfield is not working but my label is?
body: <p>I have a very strange problem trying to get the value from an ASP.NET HiddenField control in a page using a master page. I have a page were I show a label and a hiddenfield control. I set the value to both controls when the user calls the page and I can see the value assigned when I view the HTML source:</p>
  <p>This is my setup.</p>
  <pre><code>test.aspx
  
  &lt;asp:Label ID=&quot;lbl_total&quot; runat=&quot;server&quot;&gt;&lt;/asp:Label&gt;
  &lt;asp:HiddenField ID=&quot;hdn_total&quot; runat=&quot;server&quot; /&gt;
  &lt;asp:Button ID=&quot;btn_test&quot; runat=&quot;server&quot; Text=&quot;Get Value&quot; OnClick=&quot;btn_test_Click&quot; /&gt;
  </code></pre>
  <p>In the code behind I set the value for both controls:</p>
  <pre><code>lbl_total.Text = &quot;10&quot;;
  hdn_total.Value = &quot;10&quot;;
  </code></pre>
  <p>When I opens text.aspx, I can see the value correctly set in the controls:</p>
  <pre><code>&lt;span id=&quot;panel_body_lbl_label&quot;&gt;10&lt;/span&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;ctl00$panel_body$hdn_total&quot; id=&quot;panel_body_hdn_total&quot; value=&quot;10&quot; /&gt; 
  </code></pre>
  <p>So far so good. The problem starts when I press the button control:</p>
  <pre><code>&lt;asp:Button ID=&quot;btn_test&quot; runat=&quot;server&quot; Text=&quot;Get Value&quot; OnClick=&quot;btn_test_Click&quot; /&gt;
  </code></pre>
  <p>When I press the submit button, in the code behind I have the following:</p>
  <pre><code>protected void btn_test_Click(object sender, EventArgs e)
  {
     try
     {
      Response.Write(&quot;hdn_total=&quot; + hdn_total.Value);
     }
     catch(Exception ex)
     {
         Response.Write(ex.message);
     }
  }
  </code></pre>
  <p>and the value of hdn_total.Value is empty. I can however still get the value of lbl_total.Text</p>
  <p>I have never seen a problem like this occur. Normally I always can get the value from a hiddenfield without any problems. I must be missing something really obvious but after two days looking at this I need some help to figure out this problem, thanks a lot.</p>
  <p>UPDATE - Adding my .aspx.cs file below without the obvious namespaces</p>
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      try
      {
          if (!IsPostBack)
          {
          }
      }
      catch (Exception ex)
      {
          Response.Write(ex.Message + ex.Source + ex.InnerException + ex.StackTrace);
      }
  }
  
  protected void btn_test_Click(object sender, EventArgs e)
  {
      try
      {
          Response.Write(&quot;lbl_total=&quot; + lbl_total.Text);
          Response.Write(&quot;hdn_total=&quot; + hdn_total.Value.Trim());
          return;
      }
      catch (Exception ex)
      { Response.Write(&quot;&lt;!-- debug =&quot; + ex.Message + ex.InnerException + ex.Source + ex.StackTrace + &quot;--&gt;&quot;); }
  }
  
  protected void grdTest_DataBound(object sender, EventArgs e)
  {
      if (ShoppingCart.Instance.Items == null)
      {
          cart_footer.Visible = false;
      }
      else
      {
          if (grdCart.Items.Count() == 0)
          { return; }
  
          string price_format = SiteConfiguration.configValue(&quot;price_format&quot;);
          string total = String.Format(price_format, ShoppingCart.Instance.GetSubTotal());
  
          if (!string.IsNullOrEmpty(total))
          {
              lbl_total.Text = total;
              hdn_total.Value = Convert.ToString(ShoppingCart.Instance.GetSubTotal());
          }
          else
          {
              cart_footer.Visible = false;
          }
      }
  }
  </code></pre>
  <p>I am using a listview on the test.aspx page BUT my lbl_total and hdn_total controls are outside the listview so that shouldn't make any difference. I set the value to both controls on my OnDataBound because I retrieve the values from the listview. I do get the values correctly for both controls when I access the test.aspx file as I can see them when I view the HTML source code in the browser. The problem is when I click on the submit button, it supposed to read both controls values, that's all but I only get the value for the lbl_test and not the hdn_test and that's what is very strange.</p>