• How to maintain scroll position of a DIV on Postback in ASP.NET

    by  • April 24, 2014 • Microsoft ASP.NET • 0 Comments

    We know that scroll bar comes back to its original position after Postback in an ASP.NET page. This scroll bar may be for the page or DIV. Many times you need to keep the scroll position after you click a button on the page. The page scroll position can be maintained easily by setting a page property. This feature is useful when you have large pages and scrolling is necessary.  There are three ways to set the page property.

    • You can set in page directive

    • You can set it programmatically

    • You can set it in web.config in <system.web> section

    Sometimes we need to add scrolling for DIV and the DIV will also lose its scroll position after Postback. This article will show the code snippet to maintain scroll position of a DIV on Postback. I am using JavaScript here in my article to retain the scroll position but it can also be done with jQuery and there are also different ways to do it. Let’s see the code now.

    Create a website in Visual Studio and add a web form

    Add following code in aspx page

     

    Now add following JavaScript code

    Download complete sample code from below link




    Namecheap.com
    Avatar of GetCodeSnippet.com

    About

    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply