Last post Mar 07, 2012 01:52 AM by Steven Cheng - MSFT
Feb 28, 2012 08:54 PM|Dalmighty|LINK
I got a little problem that for some reason I'm having a mental blank on.
I got this snippit of code which I want to save a set of XElement attributes as a page variable to avoid code duplication, but I can't seem to do it.
so I want to save actualFigures as a page variable so I could reference in other methods.
Thanks for any replies.
IEnumerable<XElement> actualElement = from x in xDoc.Root.Elements("dataset")
where x.Attribute("seriesName").Value == "Actual"
var actualFigures = actualElement.Elements("set");
Mar 01, 2012 08:51 PM|Decker Dong - MSFT|LINK
What's the matter now？Have you got anything wrong or exceptions thrown out？
Mar 07, 2012 01:52 AM|Steven Cheng - MSFT|LINK
Generally due to the page lifecycle, if you simply define a page class variable to hold some data, it will not be shared between multiple page requests(event across different postback events like button click...). So if you want to share data across multiple
postbacks on the same page, you can consider storing it into page's ViewState:
#How to: Save Values in View State
#Understanding ASP.NET View State
#ViewState in ASP.NET 2.0
If you want to make the data further shared across multiple pages (no matter get or post requests), ViewState no longer works. You need to consider other storage such as SessionState(per user session) or ASP.NET Cache (globally wide):
#ASP.NET Page Life Cycle Overview