[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Minimizing viewstate on pages

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
CARLOSVILLACRIZ
Asked:
CARLOSVILLACRIZ
1 Solution
 
mmarinovCommented:
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
 
RejojohnyCommented:
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
 
RejojohnyCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
RejojohnyCommented:
0
 
smolamCommented:
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
 
raterusCommented:
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
 
CARLOSVILLACRIZAuthor Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now