Prevent aspx page from scrolling to top on postback

I have a aspx that when the page postback it scrolls all of the way to the top of the from on a postback.  I'm trying to prevent this from happening but i cant find a solution.  I have tried setting MaintainScrollPositionOnPostback="true" and i have found a couple of examples of javascript that should prevent this from happening but i cant seen to find a solution.  

I am using a masterpage and i am guessing that is probably why i cant get this to work.  I looking for a solution to this problem.  Any help would be greatly appreciated.

Im using, visual studio 2010

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Have you tried implementing ajax?

If you do a partial postback the page won't scroll.

The simplest way to do this is to add an <asp:updatepanel> around the offending control that causes the control.

Pattern is:
 <!-- top of page . . .  note there could only be one per page so if you have one on the master page you're fine. -->
   <asp:ScriptManager runat="server" id="sm1" />

<!-- in your content page -->
<asp:UpdatePanel runat="server" id="up1">
     <!--your controls go here -->

Open in new window

I have this.MaintainScrollPositionOnPostBack = true;  in the Page_load of the page that uses the Master page.
John Gates, CISSPSecurity ProfessionalCommented:
Put this in your page directive:  smartNavigation="True"

<%@ Page Language="vb" AutoEventWireup="false" Inherits="yourapp" smartNavigation="True" Codebehind="yourpage.aspx.vb"  meta:resourcekey="PageResource1" %>

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

John Gates, CISSPSecurity ProfessionalCommented:
smartNavigation is the replacement for MaintainScrollPositionOnPostBack = true

Mike_StevensAuthor Commented:
I should have mentioned in my original post that i am using a update panel.

I tried all of the above suggestions and still the same result.
Have you tried this solution?

Possible Solution
John Gates, CISSPSecurity ProfessionalCommented:
I use an update panel on the page where I gave you the sample directive...  Works fine and remains where it is without scrolling back...  Did you actually try the smartNavigation = True or just assume it didn't work?  The page that directive comes from is an online payment page with an ajax enabled blockui for credit card information submission.  It relies on a scriptmanager on the page..  But I have learned how and where you add the update panel etc in the code makes a difference..  Maybe if you post your codebehind page and the aspx page we can help further...

John Gates, CISSPSecurity ProfessionalCommented:
<%@ Page Language="C#" AutoEventWireup="true" MaintainScrollPositionOnPostback="true" CodeBehind="WebForm7.aspx.cs" Inherits="MyProject.WebForm7" %>

Is a way to address this too.  I said it backwards in my first post as smartNavigation=True is the old method...  I use .NET 4.5 on my site and I find the directive still works better then the MaintainScrollPositionOnPostback but I find putting it in the page directive of the aspx seems to yield better results than in the code behind in my experience anyway.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kyle AbrahamsSenior .Net DeveloperCommented:
what kind of controls are you working with?  And what's within the update panel?

Is it possible to narrow down the size of the update panel or what's overflowing it that's causing it to scroll?

Can you post your front end?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.