title: Set and Get value in ViewState when page postback
body: <p>When my page loads it is calling <code>set</code> method followed by <code>get</code> method.  But when I click on link button in treeview, then first <code>get</code> method is called followed by <code>set</code> method. I think it is not correct as I expect the <code>set</code> method to be called before <code>get</code> method.<img src="https://i.stack.imgur.com/dIsnB.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/zjwHp.jpg" alt="enter image description here"></p>
  
  <p>Here image icon are first <code>set</code> and then <code>get</code> on pageload, but when click on link button it is postback and calls <code>get</code> method and then <code>set</code>, due to this  <code>ViewState["ExtensionOrFile"]</code> returns null in <code>get</code> when link button is clicked.</p>
  
  <pre><code>get
  {
      string s = (string)ViewState["ExtensionOrFile"];
      if(s == null) return "";
      return s;
  } 
  set{ ViewState["ExtensionOrFile"] = value; } 
  </code></pre>
  
  <p>when pageload it calling first <code>Set</code> and then <code>Get</code> it is correct for my page but when page post back on link button click it calling first <code>Get</code> and then <code>Set</code> it is not correct for me..becase it return null value and then <code>Set</code> value in Viewstate["ExtensionOrFile"].</p>
  
  <p><img src="https://i.stack.imgur.com/aiS4o.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/MpxhP.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/VVVQ6.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/AooZL.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/GAZwU.jpg" alt="enter image description here"></p>