How do I retain data after the page has been reloaded?

F

Flyguy

I am trying to keep from reloading my XmlDocument every time my page reloads.
To do this I am using ViewState.

System.Xml.XmlDocument myDataXmlDoc = new System.Xml.XmlDocument();
myDataXmlDoc.Load("myData.xml");
ViewState["myDataXmlDoc"] = myDataXmlDoc;

When I do this I get the following error:

Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as
serializable.

Please let me know of anything I can do.
 
V

Vinay Khaitan

I think, you need to reload xml document again. you need to store xml
document as string in viewstate, and then load it again.
In fact sometimes xml string are used for loading different kind of objects
( like dataset).
 
B

bruce barker

unless you xml is really small (couple hundred bytes), this is a very poor
design. viewstate is shipped to the browser, then shipped back using up
brandwidth, and making your site slow.

-- bruce (sqlwork.com)


Mark Rae said:
Please let me know of anything I can do.

ViewState["myDataXmlDoc"] = myDataXmlDoc.OuterXml;

Then, when you need it again:

System.Xml.XmlDocument myDataXmlDoc = new System.Xml.XmlDocument();
myDataXmlDoc.Load(ViewState["myDataXmlDoc"].ToString());
 
V

Vinay Khaitan

You are right that viewstate should be used for very less amount of data
only. And also, XML loading time can be higher for large xmls. But you
really have very little choice. You can use Session variable to store it
too. But that would amount to using more memory per session.
You can also use SQL server as state server to reduce memory requirements.
Or you can write custom code to store this loaded xml to sql server?

--
Vinay Khaitan
[Windows Forms Layout Control]
http://www.smart-components.com/
----------------------------------------------------------------


bruce barker said:
unless you xml is really small (couple hundred bytes), this is a very poor
design. viewstate is shipped to the browser, then shipped back using up
brandwidth, and making your site slow.

-- bruce (sqlwork.com)


Mark Rae said:
Please let me know of anything I can do.

ViewState["myDataXmlDoc"] = myDataXmlDoc.OuterXml;

Then, when you need it again:

System.Xml.XmlDocument myDataXmlDoc = new System.Xml.XmlDocument();
myDataXmlDoc.Load(ViewState["myDataXmlDoc"].ToString());
 
A

Allen Chen [MSFT]

Hi,

I see some suggestions have been provided by MVPs. Have you got the
expected answer? Do you have further questions? Please don't hesitate to
let me know if you need further assistance. I'll try my best to followup.

Regards,
Allen Chen
Microsoft Online Community Support
--------------------
| Thread-Topic: How do I retain data after the page has been reloaded?
| thread-index: AclA590GxxDmPmYSQL+JidLTq/9hJg==
| From: =?Utf-8?B?Rmx5Z3V5?= <[email protected]>
| Subject: How do I retain data after the page has been reloaded?
| Date: Fri, 7 Nov 2008 06:48:14 -0800
| Lines: 15
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:79432
| NNTP-Posting-Host: tk2msftsbfm01.phx.gbl 10.40.244.148
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I am trying to keep from reloading my XmlDocument every time my page
reloads.
| To do this I am using ViewState.
|
| System.Xml.XmlDocument myDataXmlDoc = new System.Xml.XmlDocument();
| myDataXmlDoc.Load("myData.xml");
| ViewState["myDataXmlDoc"] = myDataXmlDoc;
|
| When I do this I get the following error:
|
| Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0,
| Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as
| serializable.
|
| Please let me know of anything I can do.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top