eZine4i.com - Free Articles Directory From Search4i Network
   
   
 
 

ARTICLE CATEGORIES

SEARCH4i NETWORK

Follow Me on Twiter

ADVERTISEMENTS

 

TOP 5 AUTHORS

Alan Smith 532
Angelo Everton 307
Kaye Z. Marks 291
Ashish Pandey 257
Julia Bennet 256

Disable View State for a Page In ASP.NET

addthis
     
Author:

Chetas

Category: HomearrowProgramming
Summary:

You can disable a control's view state if the control does not contain any dynamic data, its value is hard-coded, or its value is assigned on every page request and you're not handling its events.

Article:
Introduction
The ASP.NET view state is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. The view state of a page is, by default, placed in a hidden form field named __VIEWSTATE. This hidden form field can easily get very large, on the order of tens of kilobytes. Not only do large view states cause slower downloads, they also lengthen postback request times because the contents of this hidden form field must be included in the HTTP post back request. Unlike most other features of ASP.NET, view state can impact web pages dramatically, not only be in page size but also in server side performance. Moreover, pages with large view states can throw unexpected errors.

A key thing to remember is that view state is enabled by default for every control on every page. Since many server controls defined on a page contribute to view state size, your page’s view state will grow very large and impact performance if left unchecked.
When to Disable View State
You can disable a control's view state if the control does not contain any dynamic data, its value is hard-coded, or its value is assigned on every page request and you're not handling its events.

A good example of a big consumer of view state is .NET’s DataGrid control. It is desirable to disable view state for a page if the page does not post back. However, if the DataGrid has sorting or paging enabled, then enabling view state is desirable.

When you complete a web page, review the controls in the page and consider what information is being passed in the view state and whether you really need all that information to be maintained. To optimize web page size, consider disabling view state in these cases:

* 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

How to Disable View State on a Page
To disable a page’s View State, add the code below in the Page class of the page. In this example, the page’s class name is ShowOrdersTablePage.

C#:

public ShowOrdersTablePage()
{
this.Init += new EventHandler(Page_Init);
}

private void Page_Init(object sender, System.EventArgs e)
{
this.EnableViewState = false;
}

Visual Basic .NET:

' Disable the View State in the page.M
Private Sub MyPage_Init_DisableViewState(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub
Source: Free Articles from ezine4i.com
About Author: emailverified

Rate It:
     

TOP

RELATED ARTICLES

bullet Project Scheduling – The Central Piece Of A Project Management Software
By:Ioan Lucian Category:Programming
bullet Why hire PHP Development Company for web development projects
By:Chris Miller Category:Programming
bullet Package Software with InstallAware Studio for Windows Installer
By:Candice Jones Category:Programming
bullet Package Software with a Free Installer
By:Candice Jones Category:Programming
bullet What to look before hiring iPhone Developer from reliable company?
By:dave Category:Programming
bullet Penny Auction Strategy for New Bidders
By:David John Category:Programming
bullet Customization In Iphone Application Development
By:Dharmraj Singh Category:Programming
bullet Driving Web-based Commerce with Magento Development
By:Jerome Smith Category:Programming
bullet Hire PHP Developers to enhance your online business
By:vivekcis Category:Programming
bullet The Zend Developer Pulse Survey – Expected Trends In The Technology In 2012
By:Chris Miller Category:Programming