Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > View State and Server caching

Reply
Thread Tools

View State and Server caching

 
 
abcd
Guest
Posts: n/a
 
      08-08-2008
My application is using ASP.NET 3.0 and My ASPX pages contain Master page,
and content page. The content page (.aspx) has various User controls (ascx).
My page view state is significantly large and I am looking for some smart way
to rfeduce the page size. So I indentified to manipulate ViewState. When page
is posted I will park the ViewState on Server and viewState will not move
back and forth. I am doing code as below in Page level by overrriding below
methods.

protected override void SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Cache.Add(str, viewState, null,
DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
CacheItemPriority.Default, null);
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 Cache[str];
}

This is not working good for me. My pages get invalid viewState errors. I am
using Workflows too. Any idea how these methods can be better tuned when a
page contains multiple user controls.

Thanks
 
Reply With Quote
 
 
 
 
Alvin Bruney [ASP.NET MVP]
Guest
Posts: n/a
 
      08-10-2008
So how is viewstate going to get to the client if you park it on the server?
It must move there eventually right? I suggest you look at reducing the size
of viewstate first but turning it off controls and pages that don't require
it. Remember, items like textbox don't need it. There's also control state
which is more efficient and tends to be lighter. However, I think you are
heading in the right direction for optimization.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------


"abcd" <> wrote in message
news:CE6F3378-9AB8-4B85-8674-...
> My application is using ASP.NET 3.0 and My ASPX pages contain Master page,
> and content page. The content page (.aspx) has various User controls
> (ascx).
> My page view state is significantly large and I am looking for some smart
> way
> to rfeduce the page size. So I indentified to manipulate ViewState. When
> page
> is posted I will park the ViewState on Server and viewState will not move
> back and forth. I am doing code as below in Page level by overrriding
> below
> methods.
>
> protected override void SavePageStateToPersistenceMedium(object
> viewState)
> {
> string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
> DateTime.Now.Ticks.ToString();
> Cache.Add(str, viewState, null,
> DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
> CacheItemPriority.Default, null);
> 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 Cache[str];
> }
>
> This is not working good for me. My pages get invalid viewState errors. I
> am
> using Workflows too. Any idea how these methods can be better tuned when a
> page contains multiple user controls.
>
> Thanks


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable page caching without disabling caching of jpegs andstylesheets etc JimLad ASP .Net 3 01-21-2010 10:13 AM
caching: Session state or Application state... spacehopper_man@yahoo.com ASP .Net 6 11-30-2005 12:21 AM
How to make a week view and day view calendar just like month view calendar in .NET ? Parthiv Joshi ASP .Net Web Controls 1 07-06-2004 03:15 PM
Fragment Caching inside page caching? Troy Simpson ASP .Net 0 01-19-2004 11:57 AM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments