title: HiddenField empty and Viewstate value null on Page_Load
body: <p>This issue started when trying to get a DevExpress <code>ASPxPopupControl</code> to show after pressing a button. Using <code>popup.ShowOnPageLoad = true;</code> didn't seem to suffice, checking the value on <code>Page_Load</code> shows it reverts to <code>false</code>, even though the code on the server definitely executed.</p>
  
  <p>So I decided to have a variable that reads from and writes to the <code>ViewState</code> so it persists. I then had the variable:</p>
  
  <pre><code>bool ShowPopup
  {
      get
      {
          if (ViewState["ShowPopup"] == null)
              return false;
          return (bool)ViewState["ShowPopup"];
      }
      set
      {
          ViewState["ShowPopup"] = value;
      }
  }
  </code></pre>
  
  <p>Which was called on the button press by simply <code>ShowPopup = true</code>. When using <code>popup.ShowOnPageLoad = ShowPopup;</code> in <code>Page_Load</code>, <code>ViewState["ShowPopup"]</code> is <code>null</code> and therefore it returns <code>false</code>.</p>
  
  <p>I then tried to use a <code>HiddenField</code>. So I changed <code>ShowPopup</code> to:</p>
  
  <pre><code>bool ShowPopup
  {
      get
      {
          return hfShowPopup.Value != "" &amp;&amp; hfShowPopup.Value.ToLower() != "false";
      }
      set
      {
          hfShowPopup.Value = value.ToString();
      }
  }
  </code></pre>
  
  <p>Again using <code>ShowPopup = true</code> on button click, when <code>ShowPopup</code> is read in <code>Page_Load</code> its value is <code>""</code> and again therefore <code>ShowPopup</code> is <code>false</code>.</p>
  
  <p>I then tried to set the <code>HiddenField</code> directly via <code>hfShowPopup.Value = "true";</code> and using </p>
  
  <pre><code>popupDuplicatePlayer.ShowOnPageLoad = hfShowPopup.Value != "" &amp;&amp; hfShowPopup.Value.ToLower() != "false";
  </code></pre>
  
  <p>in <code>Page_Load</code>, but again <code>hfShowPopup.Value</code> is empty.</p>
  
  <p>I have used a number of other variables reading from/writing to the <code>ViewState</code> in the same page and they work fine. I know that <code>ViewState</code> and <code>HiddenField</code> might not exist early in the page life cycle but there are being used in <code>Page_Load</code> and so should be fine? I also tried to access them in <code>Page_LoadComplete</code> with the same issues. There are no <code>UpdatePanel</code>s on the page so this isn't an issue, is there any other reason for this?</p>
  
  <p>I would assume that the issue with the <code>ViewState</code>, <code>HiddenField</code> <em>AND</em> the <code>ShowOnPageLoad</code> being set directly are related?</p>