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?

有帮助吗?

解决方案

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; }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top