viewstate=false doesn't work

Discussion in 'ASP .Net Web Controls' started by Trapulo, Mar 3, 2005.

  1. Trapulo

    Trapulo Guest

    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
    Trapulo, Mar 3, 2005
    #1
    1. Advertising

  2. Trapulo

    Scott M. Guest

    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 [Microsoft MVP]" <www.lulu.com/owc> wrote in message
    news:O6X%...
    > 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" <> wrote in message
    > news:%23XQ7Bu%...
    >> 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
    >>
    >>

    >
    >
    Scott M., Mar 3, 2005
    #2
    1. Advertising

  3. Trapulo

    Trapulo Guest

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

    "Scott M." <> wrote in message
    news:...
    > 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.
    >
    Trapulo, Mar 4, 2005
    #3
  4. 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;
    }

    <<<<<<<<<



    "Trapulo" <> wrote in message
    news:#XQ7Bu#...
    > 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
    >
    >
    Andrew Robinson, Mar 4, 2005
    #4
  5. Trapulo

    Scott M. Guest

    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 [Microsoft MVP]" <www.lulu.com/owc> wrote in message
    news:%...
    > 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." <> wrote in message
    > news:...
    >> 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 [Microsoft MVP]" <www.lulu.com/owc> wrote in message
    >> news:O6X%...
    >>> 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" <> wrote in message
    >>> news:%23XQ7Bu%...
    >>>> 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
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Scott M., Mar 6, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. matt del vecchio

    EnableViewState="False" doesn't work?

    matt del vecchio, Jan 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,152
    Craig Deelsnyder
    Jan 7, 2004
  2. Amar
    Replies:
    0
    Views:
    543
  3. Wayne Erfling
    Replies:
    0
    Views:
    453
    Wayne Erfling
    Oct 13, 2006
  4. Dica

    viewstate = false doesn't work

    Dica, Jun 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    413
  5. Amar
    Replies:
    0
    Views:
    209
Loading...

Share This Page