Solved

Minimizing viewstate on pages

Posted on 2004-10-20
7
323 Views
Last Modified: 2012-08-13
Hi experts,

I'd like to optimize my aspx pages for Search Engines like google. One thing I have to do is to minimize or delete the viewstate hidden input field. I'm using user controls, so in both pages and user controls I considered the tag: EnableViewState="False". The problem is that viewstate is still in the result pages.

How can I delete viewstate from my aspx result pages?

Carlos V.
0
Comment
Question by:CARLOSVILLACRIZ
7 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12366715
Hi CARLOSVILLACRIZ,

see here : http://www.dotnetjohn.com/articles/articleid71.aspx
ViewState and Performance
By default ViewState is enabled in an ASP.NET application. Developers should be aware that any data in ViewState automatically makes a round trip to the client. Because the round trips contribute to a performance overhead, it is important to make judicious use of ViewState.

This is especially important when your application contains complex controls such as a DataList or DataGrid but is generally true when you are presenting considerable information via a server control. An example might be presented a list of countries for selection ... you don't want to impose the overhead of transferring all the country text back and forth from server to client and vice versa more than is strictly necessary. It will significantly impact on response times if you don't disable the ViewState either for the page as a whole or for the specific controls causing the unnecessary overhead.

Whenever you complete a web forms page you should review the controls in the page and consider what is being passed in the ViewState and whether you really need all that information to be passed. To optimise Web page size you may want to disable ViewState in the following cases, amongst others:

when a page does not postback to itself
when there are no dynamically set control properties
when the dynamic properties are set with each request of the page
ASP.NET provides you with complete flexibility to disable ViewState. As already discussed you are able to disable ViewState at the control and page level. Additionally you may disable ViewState at the application and machine level via the web.config and machine.config files via the following directive:

<Pages enableViewState="false"/>  


Regards!
B..M
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12367235
just check by adding the attribute enableciewstate =false within the "<%@ Page"  tag .. But I have noticed that even after doing all this the "__VIEWSTATE" hidden input view is till present in the HTML page.... I am not very sure about this, but probably the session state is also maintained using the viewstate .. so even u disable it .. some information is passed in the viewstate .. this will not contain information about the values of the control but other things that the aspx page need for its processing later and the size will not change drastically on multiple submits as it would have in the case the viewstate was enabled and u have many controls in the page ...
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 500 total points
ID: 12367295
i noticed that viewstate is still shown in the HTML page when we disable sesssionstate too .. also if i had no controls within my page and just my <form> tag, it still has some viewstate .. but by removing the runat=server property for the form tag .. the viewstate is removed .. so what i could conclude is that it is toring some information about the form in the viewstate even when u disable viewstate for the page ...
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 26

Expert Comment

by:Rejojohny
ID: 12367403
0
 
LVL 7

Expert Comment

by:smolam
ID: 12367827
You could also use a provider, very powerful and very flexible:  here is an article which has source code and examples, it shows you how to put the Viewstate into a SQL database or a file or anything else you want.

http://www.thecodeproject.com/aspnet/ViewStateProvider.asp
0
 
LVL 33

Expert Comment

by:raterus
ID: 12370011
You can never completely rid yourself of the hidden viewstate form field, it's used by some system level controls.  I have read this officially, but can't seem to find it now.
0
 

Author Comment

by:CARLOSVILLACRIZ
ID: 12390127
Hi experts,

I solved this thing about the viewstate deleting all the controls and generating them using response.write... doing this any viewstate is written.. we had to do this with 2 or 3 user controls that will be in a lot of pages that must be scanned with Search Engines.. so we got the requirement to delete any dynamic or strange generated code (viewstate included)...

Thanks by your suggestions.. I'll give points to Rejojohny because he tested pages and know that disable viewstate is not possible if you have any control in your page.. is not only necessary to write: enableViewState="false"

Carlos V
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question