Click here to Skip to main content
13,356,207 members (65,930 online)
Click here to Skip to main content
Add your own
alternative version


51 bookmarked
Posted 3 Mar 2005

How to scroll an ASP.NET control into view after page load using codebehind

, 21 Mar 2005
Rate this:
Please Sign up or sign in to vote.
This simple function uses JavaScript to scroll any control into view after the page has loaded.


In some cases when an ASP.NET page loads the control, you need to focus on is not visible because it is further down the page. I have had numerous occasions when a request variable indicates which item on a long list the user is interested in viewing, this script can help by scrolling the particular item into view.


The following function I have added to a Utils.dll library for general use so is static and needs the current page as a variable.

public class Utils
   public static void FocusControlOnPageLoad(string ClientID, 
                                       System.Web.UI.Page page)




      function ScrollView()

         var el = document.getElementById('"+ClientID+@"')
         if (el != null)

      window.onload = ScrollView;



You can use this as follows:

private void Page_Load(object sender, System.EventArgs e)
Utils.FocusControlOnPageLoad(this.yourcontrol.ClientID, this.Page);

Hopes this helps someone.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Founder Tech Dept
United Kingdom United Kingdom
My Evolution:
TRS-80 Basic, Clipper, C, Better Basic, FORTRAN, C++, Visual Basic, Delphi, C#

You may also be interested in...


Comments and Discussions

GeneralThis is only MSIE specific Pin
stp8-Mar-05 0:16
memberstp8-Mar-05 0:16 
GeneralRe: This is only MSIE specific Pin
Ach1lles8-Mar-05 1:02
memberAch1lles8-Mar-05 1:02 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 21 Mar 2005
Article Copyright 2005 by Ach1lles
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid