How to Maintain a Scroll Position in a Panel With ASP.NET

A Microsoft .NET Panel control lets you contain text and other controls within the panel, and a scroll bar is set when these controls extend the height of the control. To maintain the scroll bar's position even after the user sends data, use Ajax within your ASP.NET page. The Ajax asynchronous connection to the panel maintains the scroll bar's position.


    • 1

      Open the Visual Studio software on your desktop and open the Web project you want to edit. Double-click the code file you want to use.

    • 2

      Drag and drop a panel control form the .NET toolbox to the open file. .NET automatically adds the panel object and the necessary code.

    • 3

      Click the "Design View" option and click the tab to view the HTML code. Add the following code to the "head" section of the code:

      <script type="text/javascript">
      var xPos, yPos;
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      function BeginRequestHandler(sender, args) {
      x = $get('panel').scrollLeft;
      y= $get('panel').scrollTop;
      function EndRequestHandler(sender, args) {
      $get('panel').scrollLeft = x;
      $get('panel').scrollTop = y;

      Replace "panel" with the name of your panel.

Related Searches


Related Ads

View Mobile Site