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;
{
if(!Page.IsPostBack)
{
ViewState["View"] = 1;
int count = (int)ViewState["View"];
count += 1;
ViewState["View"] = count;
lblView.Text = ViewState["View"].ToString();
}
}
count += 1;
ViewState["View"] = count;
lblView.Text = ViewState["View"].ToString();
}
}


Ranjit PowarRank #553 · 4.4K reputationPosted Feb 1, 2016, 3:55 PM EST
{
if(!Page.IsPostBack)
{
ViewState["View"]=1;
}
else
{
int count = (int)ViewState["View"];
count += 1;
ViewState["View"] = count;
lblView.Text = ViewState["View"].ToString();
}
}
If it helps you, select it as correct answer.
Vivek KumarRank #272 · 9.3K reputationPosted Feb 8, 2016, 9:40 AM EST
{
if(!Page.IsPostBack)
{
ViewState["View"]=1;
}
else
{
int count = (int)ViewState["View"];
count += 1;
ViewState["View"] = count;
lblView.Text = ViewState["View"].ToString();
}
}