ASP.NET removing the viewstate

Associate
Joined
18 Oct 2002
Posts
1,044
Hi

I'm having some problems writing an asp.net app, I need to remove the viewstate hidden input field from a form (the browser I'm writing for allocates the space for hidden form fields) . I've tried disabling at the usercontrol level, the page level, and in web.config. Is there anywhere else that might be causing this to be added?

I'm more than happy to store all my information in a session variable and all the controls i'm using are really simple ones (buttons, dropdown lists etc), so I don't know why asp.net keeps adding it....

akakjs
 
Think it should be in the control pan on the right when you either open the page your wanting it switch off on or it could be when you select a certain control on your page.

Either way I think its a property on the right that says Enable View State this needs setting to flase and it *should* then turn it off.
 
Why do you need to remove it? ASP.NET likes to keep a track of what pages are coming from which clients and there's a whole thing about keeping the viewstate in memory, on a separate viewstate server, or you can even whack the viewstates for a cluster of webservers into a database :eek:

You won't be able to get rid of it altogether - asp.net needs it to work. I think you may be able to put it into a cookie though, try looking at your web.config.

*edit, just saw the above. That may be true, never played with that...
 
Last edited:
growse said:
Why do you need to remove it? ASP.NET likes to keep a track of what pages are coming from which clients and there's a whole thing about keeping the viewstate in memory, on a separate viewstate server, or you can even whack the viewstates for a cluster of webservers into a database :eek:

You won't be able to get rid of it altogether - asp.net needs it to work. I think you may be able to put it into a cookie though, try looking at your web.config.

*edit, just saw the above. That may be true, never played with that...

Depending on what the OP is doing, the ViewState is added with the HTML of the page thus increasing the overall size of the page to download.

I've seen MANY online shopping sites where nearly 2/3rds of the web-page is ViewState data! Ridiculous!
 
[edit]sorry saw your correction[/edit]

I don't use the design-view ever (in fact if I could do it I would remove it completely), everytime you load it it pushes your HTML through a modified version of the IE rendering engine, and it comes out **** with weird formatting, etc. I have all of Visual Studio's formatting disabled, it saves me days when working on big projects....

I tried turning it off programaticly & in the @Page thing, no joy :(

akakjs
 
Last edited:
akakjs said:
[edit]sorry saw your correction[/edit]

I don't use the design-view ever (in fact if I could do it I would remove it completely), everytime you load it it pushes your HTML through a modified version of the IE rendering engine, and it comes out **** with weird formatting, etc. I have all of Visual Studio's formatting disabled, it saves me days when working on big projects....

I tried turning it off programaticly & in the @Page thing, no joy :(

akakjs

are you using the old version of visual studio then as I though the HTML rendering problem was sorted in the new version.

Just had a look in VS and you can turn it off via the code behind file, and as I said the view state is attached to the user controls themselves not the pages. so to turn it off do something like this

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        userControlID.EnableViewState = False
    End Sub
 
are you using the old version of visual studio then as I though the HTML rendering problem was sorted in the new version.
As I understand 2005's html rendering is better, but it still rearranges. I understand the logic is to minimise the difference between in the visual between the designer and internet explorer (rather a short sighted stratagy imho as I try to write cross-browser compatable websites :) ).

Doesn't really matter anyways as I want to write it in .NET 1.1 which means visual studio 2003 (I write in 1.1 at work, and switching between 2.0 and 1.1 was slowing down my coding in both, as I couldn't remember which features where in which :) ).

userControlID.EnableViewState = False

I did try that but I wasn't sure I got every thing that could create the viewstate

Does everything that inherate from the webcontrol base class have the potentual to create the viewstate?

Thanks for all the help :D

akakjs
 
Is it just the viewstate in the HTML that you have a problem with? If so, can't you just move it server side? If you also want to keep the size down, you can combine it with EnableViewState=false on everything you can find :) I'm not 100% sure it kills the hidden field completely though.. I've never checked.

I've had to move the viewstate serverside a few times when I've had to render a massive datagrid on a single page.

LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium() are the two functions you need to override IIRC.
 
Beepcake said:
LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium() are the two functions you need to override IIRC.
Cool. that seems like the best route to take for the moment, thanks for the help :D

akakjs
 
Back
Top Bottom