title: Setting a session variable before AutoPostBack fires in an asp:Button
body: <p>How would I go about setting a session variable from the click of an ASP:Button before an AutoPostBack event fires.</p>
  
  <p>Here is what I have right now, but I'm not exactly sure I'm doing this right:</p>
  
  <pre><code> &lt;asp:Button ID="CommitBTN" runat="server" PostBackUrl="~/MMR_Home.aspx" 
   onclick="CommitBTN_Click" UseSubmitBehavior="true" 
   OnClientClick='&lt;% string temp1 = "true"; Session["ClickedFlag"] = temp1; %&gt;' Text="Commit Changes to Database" /&gt;
  </code></pre>
  
  <p>Would this be the correct way of performing this action or am I going at it completely wrong?</p>
  
  <p>EDIT:</p>
  
  <p>Changed my button tag to this:</p>
  
  <pre><code> &lt;asp:Button ID="CommitBTN" runat="server" PostBackUrl="~/MMR_Home.aspx" 
   onclick="CommitBTN_Click" OnClientClick="document.getElementById('&lt;%= Hidden.ClientID
    %&gt;').value='1'" UseSubmitBehavior="true" Text="Commit Changes to Database" /&gt;
  </code></pre>
  
  <p>I receive this as my error:</p>
  
  <p>Microsoft JScript runtime error: Unable to set value of the property 'value': object is null or undefined</p>