Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am working on a ASP.NET/C# Website.

I am reading data from a database, saving it in a Dictionary

C#
Dictionary<string,> Results


and then binding it to a ASP.NET chart

C#
PieChart.Series["Series"].Points.DataBind(Results, "Key", "Value", string.Empty);


I want to change the Label of a Point when I click a button.

C#
protected void Button_Click(object sender, EventArgs e)
    {
        PieChart.Series["Series"].Points[0].Label = "abc"
    }


But the problem when I click the button, a PostBack happens and the data saved in The "Results" Dictionnary is lost as well as the Chart.

Is there a way to , not lose the data when a postback happens without having to read from the database all over again?


Thank you for any help.
Posted

Use Session variables. Google is your friend.
 
Share this answer
 
You can cache your data the first time you read from the database. Just check if the cache object still exist and if it does you just cast the cache object back to the Dictionary on every post.
See here:
http://asp.net-tutorials.com/caching/object-caching/[^]

Another new smart approach is to use ajax instead posting back just to change a label name/value.
For ajax see here:
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first[^]

That's the common ajax that many are using but depending on your experience you would rather want to dive into Script Services which you can find here:
http://msdn.microsoft.com/en-us/magazine/cc163499.aspx[^]
 
Share this answer
 
You could store Results in Session. Though, Dictionary isn't serializable, so if your session is stored to SQL Server (usually it's stored to memory), you may end up having to use something like a proxy dictionary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900