473,574 Members | 18,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Viewstate in Session

With respect to Peter Bromberg's article (
http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my
viewstate info in the Session object rather than the cache (as it is per
user info). I have tried the following but am unable to serialize the
viewstate??

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = viewState;
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return Session[str];
}

TIA

MattC
Nov 19 '05 #1
3 2067
I hunted around a bit and got this to work, however I am unsure of its
implications.

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = oStringWriter.T oString();
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return oLosFormatter.D eserialize(Sess ion[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl...
With respect to Peter Bromberg's article (
http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my
viewstate info in the Session object rather than the cache (as it is per
user info). I have tried the following but am unable to serialize the
viewstate??

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = viewState;
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return Session[str];
}

TIA

MattC

Nov 19 '05 #2
that looks ok to me

--
Regards,
Alvin Bruney
"MattC" <m@m.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I hunted around a bit and got this to work, however I am unsure of its
implications .

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = oStringWriter.T oString();
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return oLosFormatter.D eserialize(Sess ion[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl...
With respect to Peter Bromberg's article (
http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my
viewstate info in the Session object rather than the cache (as it is per
user info). I have tried the following but am unable to serialize the
viewstate??

protected override void SavePageStateTo PersistenceMedi um(object
viewState)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = viewState;
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return Session[str];
}

TIA

MattC


Nov 19 '05 #3
Is there anyway to place this information in the Cache instead (so I can set
an expiry) but where it is used per person. Using this method I realised
that the session will grow very large after a while and the session timeout
might not be quick enough.
At the moment it is appending the current Tick of the system clock, so each
request would use its own entry in the session.
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();

If I alter to:
string str = "VIEWSTATE_ " + Request.UserHos tAddress;
I can avoid this problem. However, what are the issue involved in resizing
the space required by an object in the Session.

TIA

MattC

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
that looks ok to me

--
Regards,
Alvin Bruney
"MattC" <m@m.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I hunted around a bit and got this to work, however I am unsure of its
implication s.

protected override void SavePageStateTo PersistenceMedi um(object
viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = oStringWriter.T oString();
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return oLosFormatter.D eserialize(Sess ion[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl...
With respect to Peter Bromberg's article (
http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my
viewstate info in the Session object rather than the cache (as it is per
user info). I have tried the following but am unable to serialize the
viewstate??

protected override void SavePageStateTo PersistenceMedi um(object
viewState)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Session[str] = viewState;
RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", "");
}
protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("VIEWSTATE_") )
{
throw new Exception("Inva lid viewstate key:" + str);
}
return Session[str];
}

TIA

MattC



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2249
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and disable the session state in Web.Config the VIEWSTATE variable is still maintained and stores some values. Can anyone tell what those values are for,...
1
3735
by: Ralph Soons | last post by:
Hi all, I am trying to save the viewstate in a session instead of storing it in a hidden of the webpage which is default. This because of performance reasons. When I use line 2 in combination with line 4, my application works. Using Line 1 in combination with line 3 (and of course renaming httpSessionState1 to httpSessionState) results in...
1
1700
by: Sky | last post by:
Although I've been using C# for the last month or so, and accepting out of blind faith the ViewState, I do have some nagging questions about it... can you help verify the following statements? Application is across all sessions. Session is across all pages. ViewState is sort of like Session, but for only one page. <-- Correct statement? ...
6
4333
by: clsmith66 | last post by:
Is it possible to store the same information about a control that would be saved in the ViewState in a Session state? I have a page with three treeview controls and if I enable the view state for the controls I get huge delays on postbacks, but if I disable the viewstate I lose all my information. Any sugesstions?
6
1601
by: Max | last post by:
I need an vb.net class that is invoked from aspx page, that use the viewstate/session object. This class must be store the information into viewstate/session. Can you give me an example ? Thanks
3
4554
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and set textboxes, radio buttons, etc - that viewstate is fine. Then I have a linkbutton that does a Server.Transfer over to Page2.aspx. When I...
6
1585
by: mosscliffe | last post by:
I am testing for how/when a page is posted back and I decided to use a ViewState variable in PageLoad to set up a counter, but it appears, the ViewState is cleared on each PageLoad. So then I used SESSION and that worked. Am I correct in assuming ViewState is cleared on each PageLoad or is my code incorrect. VIEWSTATE If...
2
3159
by: dotComPaJi | last post by:
Hello There, I have a simple question. In one of my program if I use ViewState then program does not work as expected(nothing is displayed in GridView but If I use Session State then it works fine. Any idea??? ----------------------------------------------- //Does not work as expected
0
7817
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8081
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8258
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3759
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2254
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.