博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

如何在ASP.NET中PostBack后保持页面的位置(滚动条位置)

Posted on 2009-06-21 22:09  sun.Lei  阅读(1039)  评论(1编辑  收藏  举报

When web pages are posted back to the server, by default user is returned to the top of the page. On a large web page, you might have a requirement to scroll down the user automatically to the last position on the page.

MaintainScrollPositionOnPostBack page property can be used to achieve this  in one of the following ways. 

  1. Application level: To set the property by default for all pages in the website, open web.config and add the attribute to the pages node.

    <pages maintainScrollPositionOnPostBack="true">

  2. Page Level: for a particular page, open the aspx and set the property

    <%@ Page MaintainScrollPositionOnPostback="true" ...

  3. Code level: to set the property programmatically

    Page.MaintainScrollPositionOnPostBack = true;

 

本文转至: http://blogs.msdn.com/webdevelopertips/archive/2009/06/08/tip-75-did-you-know-how-to-maintain-scrollposition-after-post-back.aspx

Hope this helps.


Welcome To sun.Lei Blog!!