Solved

Minimizing viewstate on pages

Posted on 2004-10-20
7
322 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now