viewstate=false doesn't work

T

Trapulo

I've a datagrid and I try to disable viewstate to avoid a lot of hidden data
in the post field (about 100kb). But this doesn't work!

<asp:DataGrid id="dgExhibitionServices" runat="server" Width="520px"
Height="17px" AutoGenerateColumns="False"
EnableViewState="False" >

If this is false or not, the viewstate and page's size don't change!
What is the problem?

My datagrid is inside a usercontrol, and the main webform contains this
userscontrol. I've this problem with all controls on my page.

thanks
 
S

Scott M.

Alvin, if you turn viewstate off for a DataGrid, then, yes the data must
still be transferred to the client, but no, that data would not be persisted
in VeiwState. In other words, once you turn off ViewState for a DataGrid,
you will notice a substantial decrease in the length of the ViewState
string. ViewState is not how the data reaches the DataGrid, so turning it
off would mean that the data would have to be re-fetched from somewhere but
the ViewState hidden form field would not be holding on to any of it.


Alvin Bruney said:
I'm not sure what you are expecting to happen, the data still needs to be
loaded into the datagrid and moved to the client. Turning off viewstate
prevents a round-trip of that data, but there will still be a single trip
which is what you are seeing.

By the way, strictly speaking, the datagrid does not store its data in
viewstate, the datagrid does contain child controls (tablecells etc) that,
in turn, store its data in viewstate.

What are you trying to accomplish?

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------


Trapulo said:
I've a datagrid and I try to disable viewstate to avoid a lot of hidden
data
in the post field (about 100kb). But this doesn't work!

<asp:DataGrid id="dgExhibitionServices" runat="server" Width="520px"
Height="17px" AutoGenerateColumns="False"
EnableViewState="False" >

If this is false or not, the viewstate and page's size don't change!
What is the problem?

My datagrid is inside a usercontrol, and the main webform contains this
userscontrol. I've this problem with all controls on my page.

thanks
 
T

Trapulo

Yes: I think I may have a great decrease of viewstate string. But with or
without enableviewstate=false, I've the same (great) length.. :(
 
A

Andrew Robinson

I have used the following to eliminate viewstate on the client. Works well
where there is a slow link and large viewstate. It could lead to issues in
other areas. Mainly that you are loading up the server cache. You are
shifting the storage from the client back to the server. You could modify
this so that is used a session id and stored the viewstate in SQL. Maybe
more than you were looking for. I found this code elseware, but modified it
a bit.

-Andrew

Using System.Web.Cache;

protected override void SavePageStateToPersistenceMedium(object
viewStateObject)
{
string viewStateKey = "VIEWSTATE_" + Guid.NewGuid();
Cache.Add(viewStateKey, viewStateObject, null,
DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
CacheItemPriority.Default, null);
RegisterHiddenField("__VIEWSTATE_KEY", viewStateKey);
RegisterHiddenField("__VIEWSTATE", "");
}

protected override object LoadPageStateFromPersistenceMedium()
{
string viewStateKey = Request.Form["__VIEWSTATE_KEY"];
if (!viewStateKey.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" +
viewStateKey);
}

object viewStateObject = Cache[viewStateKey];
Cache.Remove(viewStateKey);

return viewStateObject;
}

<<<<<<<<<
 
S

Scott M.

I didn't say you were wrong, but you said "I'm not sure what you are
expecting to happen" and it seemed obvious that what the OP was looking for
was a way to take the persisted data out of the ViewState hidden form field.
So, my reply was simply to clarify what data gets transferred where and what
the OP hopes to accomplish (answer to your question).


Alvin Bruney said:
True. I'm not sure where you think I went wrong. Care to point it out?

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------


Scott M. said:
Alvin, if you turn viewstate off for a DataGrid, then, yes the data must
still be transferred to the client, but no, that data would not be
persisted in VeiwState. In other words, once you turn off ViewState for
a DataGrid, you will notice a substantial decrease in the length of the
ViewState string. ViewState is not how the data reaches the DataGrid, so
turning it off would mean that the data would have to be re-fetched from
somewhere but the ViewState hidden form field would not be holding on to
any of it.


Alvin Bruney said:
I'm not sure what you are expecting to happen, the data still needs to
be loaded into the datagrid and moved to the client. Turning off
viewstate prevents a round-trip of that data, but there will still be a
single trip which is what you are seeing.

By the way, strictly speaking, the datagrid does not store its data in
viewstate, the datagrid does contain child controls (tablecells etc)
that, in turn, store its data in viewstate.

What are you trying to accomplish?

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------


I've a datagrid and I try to disable viewstate to avoid a lot of hidden
data
in the post field (about 100kb). But this doesn't work!

<asp:DataGrid id="dgExhibitionServices" runat="server" Width="520px"
Height="17px" AutoGenerateColumns="False"
EnableViewState="False" >

If this is false or not, the viewstate and page's size don't change!
What is the problem?

My datagrid is inside a usercontrol, and the main webform contains this
userscontrol. I've this problem with all controls on my page.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top