Asp.net property value set to zero on button click
<p>On my ASP.net page I am assigning a session variable to a private property on <code>Page_Load</code></p>

<pre><code>private int userid{ get; set;} 

if (!IsPostBack)
{
   if (Session["userid"] != null)
   {
       userid= int.Parse(Session["userid"].ToString());
   }
}
</code></pre>

<p>And in my Add button click event I am using <code>userid</code></p>

<pre><code>protected void btnAdd_Click(object sender, EventArgs e)
{
  doSomething(userid);
}
</code></pre>

<p>Initially the value is retrieved and stored in <code>userid</code> property but in <code>btnAdd_Click</code>, the <code>userid</code> becomes 0. I moved the code out of <code>if(!IsPostBack)</code> block, that fixed the problem but left me wondering what set my <code>userid</code> property to <code>zero</code> once it is already set on page load. Not clear whether on button click a new instance of the page is returned or what? Any guidance?</p>
