0

Before I expose my problem, let me explain the reason why I ask this question again, after all others have been answered.

Short answer:

None of those worked for me.

Long answer:

I've been searching this topic, for over 1 year already and still got this problem unresolved.

  • I've tried javascript "solutions", a lot of them really, none have worked;
  • I've tried the MaintainScrollPositionOnPostback="true" directive, in Masterpage and in Webconfig as well;
  • I've tried the Page.SmartNavigation (which is obsolete) as well, and again nothing;
  • I've tried countless "solutions" to no avail;

I use a Masterpage and UpdatePanels in every Contentpage.

So it's starting to get annoying not being able to resolve this.

I've read somewhere that the MaintainScrollPositionOnPostback property no longer works with any of the browsers, but I might have misread that.

I'd appreciate your help :)!

Best regards!

Kévin Bibollet
  • 3,573
  • 1
  • 15
  • 33
  • I haven't checked this for a long time since I moved from webforms to mvc. I will check tomorrow and get back to you on this. – Gagan Deep Mar 12 '19 at 15:15
  • @GaganDeep I'm very greatful for your effort! – Tiago Almeida Mar 12 '19 at 16:30
  • hey @Tiago , is your postback element inside update panel or outside of it? – Gagan Deep Mar 13 '19 at 05:02
  • @GaganDeep Hi again! Yes, every Postback is inside the UpdatePanel. – Tiago Almeida Mar 13 '19 at 10:52
  • I tried that. I have a lot of empty space at the top of my page to enable scroll and a button at the bottom, when i hit the button it creates a postback to server but scroll position of the page remains intact. Also because this is an async postback page scroll position should remain as it is because page is not reloaded. I have tried this in Chrome Version 72.0.3626.121 and IE 11 both. – Gagan Deep Mar 13 '19 at 10:59
  • This is so odd, could it be from the EnableEventValidation="false"? at the top of the aspx code? <%@ Page Title="" Language="C#" EnableEventValidation="false" ....%> – Tiago Almeida Mar 13 '19 at 15:09
  • @GaganDeep Ok, after what you told me, I tried creating a new page, with only two controls, one button and one Textbox, after that I set the AutoPostback and CausesValidation to "true" and the corresponding procedures to the button onClick. I then started to trial and error with the code I had on the other pages, and found out that the culprit is the "control.Focus()". Every time I try to set the focus on another control, the Scroll goes up. Is there a way to set the Focus without Scrolling all the way up? – Tiago Almeida Mar 13 '19 at 15:32
  • Oh god. I am afraid if you set the focus to a control the page will scroll to the position where control is visible. But it can't be that you want two things at the same time : focusing on a control and keeping the scroll position. You need to chose one if they are not in one view height. – Gagan Deep Mar 13 '19 at 15:44
  • But I am glad you know what was happening in your code. – Gagan Deep Mar 13 '19 at 15:48
  • @GaganDeep Oh well, I guess I'll have to choose the Scroll position, it gets increasingly annoying trying to use the page and having it constantly jumping around. – Tiago Almeida Mar 13 '19 at 16:04

1 Answers1

1

For future reference.

My problem resided in the code itself, using Control.Focus() "conflits" with the Scroll position.

As @GaganDeep helpfully explained, one cannot use Control.Focus() and MaintainScrollPositionOnPostback="true" and the same time, as the Focus() Scrolls the page to the position of the referenced Control.

Thank you for your help! I was really struggling with this one, never thought it could be such a "simple" thing.