Javascript Scroll to Top of Page for Post Back Element ID

Posted: August 24, 2010 in ASP.Net, Javascript

You can use the following piece of Javascript to scroll to the top of a page based on a post back element id:

Copy this piece of code into your ASP.Net page.

<script type="text/javascript">
   // Script to get the element that caused the post back
    var postBackElementID;
    function InitializeRequestHandler(sender, args){postBackElementID = args.get_postBackElement().id.substring(args.get_postBackElement().id.lastIndexOf("_") + 1);}


   // Function to handle scrolling to top of page between wizard steps
   function EndRequestHandler(sender, args)
      if (postBackElementID == "YourElementID1" | postBackElementID == "YourElementID2") 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s