20 Sep 2007

How To preserve the page scroll position during a PostBack

There are 3 ways to maintain the page scroll position after postbacks in ASP.NET 2.0:

  1. In the page declaration:

    <%@ Page Language="C#" MaintainScrollPositionOnPostback="true" %>

  2. Programmatically, with the "MaintainScrollPositionOnPostback" (default = false) property for the page:

    protected void Page_Load(object sender, EventArgs e)
    {
        MaintainScrollPositionOnPostBack = true;
    }

  3. Configuring the "maintainScrollPositionOnPostBack" attribute for the "pages" element in the web.config:

    <system.web>
        <pages maintainScrollPositionOnPostBack="true" />
    </system.web>

Methods 1 and 2: the scroll position will be maintained only for the current page.

Method 3: the scroll position will be maintained for all the web site pages.

HTH

Categories: ASP.NET | Code box

Currently rated 4.2 by 6 people

  • Currently 4.166667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

Gravatar

May 16 2008 14:55