Click here to Skip to main content
12,554,623 members (55,465 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked

Maintain Scroll Position Problem fix for Chrome.

, 14 Jun 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
How to maintain scroll position of a long page with vertical scrollbar in browser other than IE.
In most of our long pages which appear in the browser with vertical scrollbar, we need to maintain the scroll prosition after postback for better user experience.

To achieve this, there is a property defined in the Page class called MaintainScrollPositionOnPostBack. We just need to set it to true at server side like the following code snippet.
this.MaintainScrollPositionOnPostBack = true;

This works perfectely fine on all IE browsers but does not work when you are using Chrome. To maintain the scroll position on Chrome or any other browser, you need to add definitions specific to a browser. For this, ASP.NET has provided Browser Deninition file (.browser), where we can define the definitions for individual browser. ASP.NET uses this information in the request header to determine what type of browser has made the request. ASP.NET identifies this using the refID attribute defined in the .browser file, then ASP.NET uses the defenitions defined .browser file to determine the capablilites of the browser. ASP.NET control adapters use this information to render the client scripts and HTML according to the browser type, so that it will be compatible with the requester browser.

To support the scroll position capability in Chrome, you need to follow the steps given below:
  1. Add the following line of code in the Page_Load of the page for which you want to maintain the scroll position.
    this.MaintainScrollPositionOnPostBack = true;
  2. Right click on the project.
  3. Click on “Add” -> “Add New Item”.
  4. In the “Add New Item” window, select “Browser File” and click “Add”.
  5. Application will ask you to place this file in “App_Browsers” folder, click “Yes”
  6. Now add the capability of maintaining the scroll position as follows:
      <browser refID="Safari1Plus">
          <capability name="supportsMaintainScrollPositionOnPostback" 
              value="true" />

To know more about .browser file, you can visit MSDN [^].


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Prakash Kalakoti
India India
Its me Smile | :)

You may also be interested in...


Comments and Discussions

PraiseAwesome Geek!!! Pin
Mahesh Shivale5-May-16 19:45
professionalMahesh Shivale5-May-16 19:45 
QuestionSafari1Plus was reported as error Pin
Michael Freidgeim14-Jan-16 12:52
memberMichael Freidgeim14-Jan-16 12:52 
QuestionIt worked! Pin
cmccreedy15-Sep-15 5:07
membercmccreedy15-Sep-15 5:07 
QuestionThanks Pin
Member 1140813429-Apr-15 20:52
memberMember 1140813429-Apr-15 20:52 
QuestionForum for tip/trick: Maintain Scroll Position Problem fix for Chrome. Pin
papu1234515-Feb-14 7:42
memberpapu1234515-Feb-14 7:42 
AnswerRe: Forum for tip/trick: Maintain Scroll Position Problem fix for Chrome. Pin
vbwyrde17-Feb-14 8:47
membervbwyrde17-Feb-14 8:47 
GeneralRe: Forum for tip/trick: Maintain Scroll Position Problem fix for Chrome. Pin
papu1234519-Jun-14 2:10
memberpapu1234519-Jun-14 2:10 
QuestionIts working in IE and Mozilla Pin
AndrewsBose14-Jun-12 2:20
memberAndrewsBose14-Jun-12 2:20 
GeneralMy vote of 5 Pin
adityapanday14-May-12 19:49
memberadityapanday14-May-12 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 15 Jun 2011
Article Copyright 2011 by Prakash Kalakoti
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid