473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ViewState too large

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?
Nov 19 '05 #1
6 4319

Well seems like your solution is to look for otherways to store viewstate,
rather than as part of the page html. do a search for storing viewstate in
session or db in google. For a start take a look at the following article

http://aspalliance.com/472

Good Luck
--
Kumar Reddi
http://kumarreddi.blogspot.com

"clsmith66" <cl*******@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
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?

Nov 19 '05 #2
There are probably several ways to tackle this but here is how I have done
it in the past.

You will need to override two methods for your control.
protected override void LoadViewState(object savedState);
protected override object SaveViewState()

SaveViewState returns the object that should be placed into viewstate. So
you intercept it and store it into session

protected override object SaveViewState()
{
//this will load the viewstate as normal
object o = base.SaveViewState();

//store it into session
System.Web.HttpContext.Current.Session[this.ID] = o;

//i think you need to return something (not null) in order for
LoadViewState
return new object();
}

protected override void LoadViewState( object savedState )
{
//load the savedState from Session
savedState = System.Web.HttpContext.Current.Session[this.ID];

//call base constructor
base.LoadViewState( savedState );
}

HTH,

bill
"clsmith66" <cl*******@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
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?

Nov 19 '05 #3
surely storing the view state on the server could lead to different
behaviour when the user makes use of the 'back' and forward' buttons on a
browser?

Ollie Riches

"William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
news:O0****************@TK2MSFTNGP12.phx.gbl...
There are probably several ways to tackle this but here is how I have done
it in the past.

You will need to override two methods for your control.
protected override void LoadViewState(object savedState);
protected override object SaveViewState()

SaveViewState returns the object that should be placed into viewstate. So
you intercept it and store it into session

protected override object SaveViewState()
{
//this will load the viewstate as normal
object o = base.SaveViewState();

//store it into session
System.Web.HttpContext.Current.Session[this.ID] = o;

//i think you need to return something (not null) in order for
LoadViewState
return new object();
}

protected override void LoadViewState( object savedState )
{
//load the savedState from Session
savedState = System.Web.HttpContext.Current.Session[this.ID];

//call base constructor
base.LoadViewState( savedState );
}

HTH,

bill
"clsmith66" <cl*******@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
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?


Nov 19 '05 #4
you store a guid on the page in a hidden field, so you can find the matching
viewstate. if the viewstate can not be found (deleted from cache) redirect
to the page.

-- bruce (sqlwork.com)

"Ollie" <why do they need this!!!!> wrote in message
news:e0******************@TK2MSFTNGP09.phx.gbl...
| surely storing the view state on the server could lead to different
| behaviour when the user makes use of the 'back' and forward' buttons on a
| browser?
|
| Ollie Riches
|
| "William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
| news:O0****************@TK2MSFTNGP12.phx.gbl...
| > There are probably several ways to tackle this but here is how I have
done
| > it in the past.
| >
| > You will need to override two methods for your control.
| > protected override void LoadViewState(object savedState);
| > protected override object SaveViewState()
| >
| > SaveViewState returns the object that should be placed into viewstate.
So
| > you intercept it and store it into session
| >
| > protected override object SaveViewState()
| > {
| > //this will load the viewstate as normal
| > object o = base.SaveViewState();
| >
| > //store it into session
| > System.Web.HttpContext.Current.Session[this.ID] = o;
| >
| > //i think you need to return something (not null) in order for
| > LoadViewState
| > return new object();
| > }
| >
| > protected override void LoadViewState( object savedState )
| > {
| > //load the savedState from Session
| > savedState = System.Web.HttpContext.Current.Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewState( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@discussions.microsoft.com> wrote in message
| > news:47**********************************@microsof t.com...
| >> 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?
| >
| >
|
|
Nov 19 '05 #5
nice idea I like it are there any drawbacks to this approach of handling
viewstate?

Ollie Riches

"bruce barker" <no***********@safeco.com> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
you store a guid on the page in a hidden field, so you can find the matching viewstate. if the viewstate can not be found (deleted from cache) redirect
to the page.

-- bruce (sqlwork.com)

"Ollie" <why do they need this!!!!> wrote in message
news:e0******************@TK2MSFTNGP09.phx.gbl...
| surely storing the view state on the server could lead to different
| behaviour when the user makes use of the 'back' and forward' buttons on a | browser?
|
| Ollie Riches
|
| "William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
| news:O0****************@TK2MSFTNGP12.phx.gbl...
| > There are probably several ways to tackle this but here is how I have
done
| > it in the past.
| >
| > You will need to override two methods for your control.
| > protected override void LoadViewState(object savedState);
| > protected override object SaveViewState()
| >
| > SaveViewState returns the object that should be placed into viewstate.
So
| > you intercept it and store it into session
| >
| > protected override object SaveViewState()
| > {
| > //this will load the viewstate as normal
| > object o = base.SaveViewState();
| >
| > //store it into session
| > System.Web.HttpContext.Current.Session[this.ID] = o;
| >
| > //i think you need to return something (not null) in order for
| > LoadViewState
| > return new object();
| > }
| >
| > protected override void LoadViewState( object savedState )
| > {
| > //load the savedState from Session
| > savedState = System.Web.HttpContext.Current.Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewState( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@discussions.microsoft.com> wrote in message
| > news:47**********************************@microsof t.com...
| >> 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?
| >
| >
|
|

Nov 19 '05 #6
The size will become prohibitive if you site has a lot of hits, and you have
to decide at what point you want to remove the server side storage of the
viewstate. IOW how many "backs" do you want to allow your user to do?

And then you have to decide how you want to handle no viewstate recorded for
the page. (you have purged the record from memory).

The easiest (and arguably lamest way), is to save the viewstate with the
hidden field GUID suggested by Bruce. Then if the GUID doesn't match the
GUID of the object saved into Session, you could display and error message
for the user telling them, they can't hit the back button, please use the
navigation provided on the page.

I am not sure what type of information you are saving in viewstate, but on a
page I was serializing a DataTable to the page, it become prohibitive in
viewstate after 20 records or so (noticeably slower). I just saved the
query used to build the DataTable into viewstate, much smaller. I am
placing more load on my SQL, but Sql is better at running queries than the
framework deserializing 30K of viewstate.

So you might be able to save the instructions for creating the large amount
of data and you could bypass the whole issue entirely.

bill
"Ollie" <ol**********@hotmail.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
nice idea I like it are there any drawbacks to this approach of handling
viewstate?

Ollie Riches

"bruce barker" <no***********@safeco.com> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
you store a guid on the page in a hidden field, so you can find the matching
viewstate. if the viewstate can not be found (deleted from cache) redirect to the page.

-- bruce (sqlwork.com)

"Ollie" <why do they need this!!!!> wrote in message
news:e0******************@TK2MSFTNGP09.phx.gbl...
| surely storing the view state on the server could lead to different
| behaviour when the user makes use of the 'back' and forward' buttons on a
| browser?
|
| Ollie Riches
|
| "William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
| news:O0****************@TK2MSFTNGP12.phx.gbl...
| > There are probably several ways to tackle this but here is how I

have done
| > it in the past.
| >
| > You will need to override two methods for your control.
| > protected override void LoadViewState(object savedState);
| > protected override object SaveViewState()
| >
| > SaveViewState returns the object that should be placed into viewstate. So
| > you intercept it and store it into session
| >
| > protected override object SaveViewState()
| > {
| > //this will load the viewstate as normal
| > object o = base.SaveViewState();
| >
| > //store it into session
| > System.Web.HttpContext.Current.Session[this.ID] = o;
| >
| > //i think you need to return something (not null) in order for
| > LoadViewState
| > return new object();
| > }
| >
| > protected override void LoadViewState( object savedState )
| > {
| > //load the savedState from Session
| > savedState = System.Web.HttpContext.Current.Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewState( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@discussions.microsoft.com> wrote in message
| > news:47**********************************@microsof t.com...
| >> 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?
| >
| >
|
|


Nov 19 '05 #7

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

Similar topics

3
by: Brian Henry | last post by:
for my <input type="hidden" name="__VIEWSTATE" on output forms... the value of the __VIEWSTATE is over 10 pages long! it makes forms load so slow, why is it that long and what can i do about it?!...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
10
by: Steve Richter | last post by:
I have some potentially large objects I would like to store in the viewstate of a user control. Large as in an entire email message. Is ViewState not the sort of place to store such an object? I...
7
by: Mantorok | last post by:
It's not unusual (to be lo....cough) for me to have VIEWSTATE ranging from 1 full page to several pages..... This seems in-efficient - any ideas how to reduce the thing? Thanks Kev
3
by: Justin | last post by:
I have aspx pages with 10 checkboxlist controls. total individual checkbox (the sum of individual checbox in those 10 checkboxlists) on the page is about 1710. You can imagine how large the...
6
by: AAOMTim | last post by:
I have a large ViewState and I've heard I can save the ViewState in a sesison object. What are the advantages of doing so and how do I do it? I've been told that I am gettign DNS timeouts because...
2
by: Nemisis | last post by:
Hi everyone, I have 2 pages, PageA and PageB. On PageA i allow our users to update a details of a record using textboxes, dropdownlists etc. When a user clicks on a button on PageA, i would...
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
9
by: =?Utf-8?B?TUNN?= | last post by:
I'm sure the answer to my question varies depending on the situation, but I am looking for a general "best practice". If I have an asp.net application and I load certain data from a database,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.