473,545 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4331

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*******@disc ussions.microso ft.com> wrote in message
news:47******** *************** ***********@mic rosoft.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(o bject 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.SaveViewSt ate();

//store it into session
System.Web.Http Context.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.Http Context.Current .Session[this.ID];

//call base constructor
base.LoadViewSt ate( savedState );
}

HTH,

bill
"clsmith66" <cl*******@disc ussions.microso ft.com> wrote in message
news:47******** *************** ***********@mic rosoft.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_fdrs ucks.com> wrote in message
news:O0******** ********@TK2MSF TNGP12.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(o bject 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.SaveViewSt ate();

//store it into session
System.Web.Http Context.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.Http Context.Current .Session[this.ID];

//call base constructor
base.LoadViewSt ate( savedState );
}

HTH,

bill
"clsmith66" <cl*******@disc ussions.microso ft.com> wrote in message
news:47******** *************** ***********@mic rosoft.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******** **********@TK2M SFTNGP09.phx.gb l...
| 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_fdrs ucks.com> wrote in message
| news:O0******** ********@TK2MSF TNGP12.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(o bject 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.SaveViewSt ate();
| >
| > //store it into session
| > System.Web.Http Context.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.Http Context.Current .Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewSt ate( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@disc ussions.microso ft.com> wrote in message
| > news:47******** *************** ***********@mic rosoft.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******** ******@TK2MSFTN GP09.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******** **********@TK2M SFTNGP09.phx.gb l...
| 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_fdrs ucks.com> wrote in message
| news:O0******** ********@TK2MSF TNGP12.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(o bject 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.SaveViewSt ate();
| >
| > //store it into session
| > System.Web.Http Context.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.Http Context.Current .Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewSt ate( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@disc ussions.microso ft.com> wrote in message
| > news:47******** *************** ***********@mic rosoft.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**********@h otmail.com> wrote in message
news:eu******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP09.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******** **********@TK2M SFTNGP09.phx.gb l...
| 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_fdrs ucks.com> wrote in message
| news:O0******** ********@TK2MSF TNGP12.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(o bject 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.SaveViewSt ate();
| >
| > //store it into session
| > System.Web.Http Context.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.Http Context.Current .Session[this.ID];
| >
| > //call base constructor
| > base.LoadViewSt ate( savedState );
| > }
| >
| > HTH,
| >
| > bill
| >
| >
| > "clsmith66" <cl*******@disc ussions.microso ft.com> wrote in message
| > news:47******** *************** ***********@mic rosoft.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
1157
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?! thanks!
2
3935
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 has changed. How can I retrieve a control's previous value from the ViewState? I know that I could save the control's previous value in a session...
10
1802
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 think my question and concern depends on what asp.net does with the view state when the page is written to the browser. Is the entire viewstate...
7
1537
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
3020
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 viewstate is. Is there anyway I can shrink the viewstate and at the same time get the values of each checkbox after postback? Thanks
6
2075
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 of the ViewState being too large. I'm trying to avoid writing manual paging routines for now. -- Tim
2
1448
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 like them to be directed to PageB. Here they can select a value from a datagrid, and then go back to PageA and continue updating the records details....
12
1900
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
2660
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, should I use ViewState to store and reload the data, or should I load the data from the database on each postback? Assume for the sake of this...
0
7468
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
7401
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
7656
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
7808
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
7423
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
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1884
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
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.