Question

I am trying to keep track of some values, which are incremented with new records from a database. The values are not sticking around when the page reloads though.

This is the property I am trying it with (just a count of all of the records I retrieve):

public int last
{
    get 
    { 
        if (ViewState["last"] != null) 
            return (int)ViewState["last"]; 
        return 0;
    }
    set 
    { 
        ViewState["last"] = value; }
    }

And I am trying to display it like this:

protected void Page_Load(object sender, EventArgs e)
{
    string output = "Last Time: " + last + ", this time: " + DbData.Count;
    last = DbData.Count;
    Response.Write(output);
}

Unfortunately, the output every time is something like: Last Time: 0, this time: 232253.

I have this site running on IIS, and I have checked to make sure that the View State was enabled:

Pages and Controls


I don't know what else to try, can anyone suggest a fix?

Was it helpful?

Solution

I'm not familiar with FusionCharts. However, ViewState lives only for the current page's lifecycle.

You might want to try SessionState which persist data between pages.

public int last
{
    get 
    { 
        if (Session["last"] != null) 
            return (int)Session["last"]; 
        return 0;
    }
    set { Session["last"] = value; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top