473,507 Members | 2,389 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 SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = viewState;
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return Session[str];
}

TIA

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

protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = oStringWriter.ToString();
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return oLosFormatter.Deserialize(Session[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9**************@TK2MSFTNGP11.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 SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = viewState;
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid 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****************@TK2MSFTNGP12.phx.gbl...
I hunted around a bit and got this to work, however I am unsure of its
implications.

protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = oStringWriter.ToString();
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return oLosFormatter.Deserialize(Session[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9**************@TK2MSFTNGP11.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 SavePageStateToPersistenceMedium(object
viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = viewState;
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid 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.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();

If I alter to:
string str = "VIEWSTATE_" + Request.UserHostAddress;
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****************@TK2MSFTNGP10.phx.gbl...
that looks ok to me

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

protected override void SavePageStateToPersistenceMedium(object
viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = oStringWriter.ToString();
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return oLosFormatter.Deserialize(Session[str].ToString());
}
"MattC" <m@m.com> wrote in message
news:O9**************@TK2MSFTNGP11.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 SavePageStateToPersistenceMedium(object
viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Session[str] = viewState;
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid 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
2241
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...
1
3724
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...
1
1697
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? ...
6
4330
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...
6
1593
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
4548
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...
6
1582
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...
2
3150
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...
0
7114
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...
0
7321
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,...
1
7034
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...
0
5623
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,...
1
5045
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...
0
3191
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...
0
1544
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 ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.