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

  • Thread starter Thread starter Flyguy
  • Start date Start date
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.
 
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).
 
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());
 
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());
 
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.
|
|
 
Back
Top