Monday, September 28, 2009

Retain Web Browser Scroll Position After a Postback

Following are the ways where the user can maintain the scroll position after a postback.

  1. In the page declaration, add <%@ Page MaintainScrollPositionOnPostback="true" %> This will maintain the scroll position of that particular page only.
  2. The user can even set via code behind also by including System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;
  3. The above two will maintain the scroll position for that page only. In order to maintain the scroll positions for the entire web site pages user has to add the Boolean attribute maintainScrollPositionOnPostBack="true"  in Web.config file of <pages>  section. 
<pages  
   buffer="[True|False]"
   enableEventValidation="[True|False]"
   enableSessionState="[True|False|ReadOnly]"
   enableViewState="[True|False]"
   enableViewStateMac="[True|False]"
   smartNavigation="[True|False]"
   autoEventWireup="[True|False]"
   pageBaseType="typename, assembly"
   userControlBaseType="typename"
   validateRequest="[True|False]"
   masterPageFile="file path"
   theme="string"
   styleSheetTheme="string"
   maxPageStateFieldLength="number"
   compilationMode="[Always|Auto|Never]"
   pageParserFilterType="string"
   viewStateEncryptionMode="[Always|Auto|Never]"
   maintainScrollPositionOnPostBack="[True|False]" 
   asyncTimeout="number"
>
   <controls>...</controls>
   <namespaces>...</namespaces>
   <tagMapping>...</tagMapping>
</pages>

    0 Comments:

    blogger templates | Make Money Online