How To Increase a View State Value on page load

Feb 1 2016 12:47 PM

 
Hi Friends ,
 
   I want to increment a variable by 1 inside the page load, that means whenever i reload the page the value of the variable should increase by one.
   i have wrote the following lines of code, but alaways getting the result as 1. i am not understanding how to increment the value....
 
 
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
ViewState["View"] = 1;
int count = (int)ViewState["View"];
count += 1;
ViewState["View"] = count;
lblView.Text = ViewState["View"].ToString();
}
 

Answers (2)