Solved

Minimizing viewstate on pages

Posted on 2004-10-20
7
321 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

13 Experts available now in Live!

Get 1:1 Help Now