Friday 2 December 2011

Maintain Scroll Position On After Postback in Asp.Net

Maintain scroll position after postback
Maintain Scroll Position on or After Postback in Asp.Net 2.0 3.5.

In this example i'm explaining different methods of maintaining scroll position on/after postback in asp.net 2.0,3.5 web pages or applications.












Method 1 .

Write below mention directive in page directive section of html source of aspx page to maintain scroll position of only one page or selected pages rather then whole web application.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  
         MaintainScrollPositionOnPostback="true"  Inherits="_Default" %>



Method 2.

To maintain scroll position programmatically use code mentione below.
System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;


Method3.

To maintain scroll position application wide or for all pages of web application we can write below mentioned code in pages section of web.config file so that we don't need to add page directive in each and every page.

<pages maintainScrollPositionOnPostBack="true">

Hope this helps.

No comments:

Post a Comment