4

Back with another web based issue.

When a control issues a postback to the server the page refreshes (Fine). The page also scrolls back to the top and loses the control that is selected. If it's relevent after the postback depending on what changes have happened controls are made visible or made hidden. The focus is lost and current scroll resets even if nothing is changed on the page visibility wise. The data inputted in Text fields is kept and so are any radiobutton/checkbox selections. The problem is tabbing is reset to index 0 and the pages scroll is sent back to the top of the page.

I am using .Net 4.0

I have tried adding MaintainScrollPositionOnPostback="true" both on the asp page itself and in the web.config to no avail. I have tried with and without the Ajax updatepanel using conditional updating triggering off when textboxes text is changed or radiobuttons are changed and the postback still causes a scroll and index loss.

Any ides would be fantastic. Ta!

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Skintkingle
  • 1,579
  • 3
  • 16
  • 28

1 Answers1

3

First of all, the MaintainScrollPositionOnPostback="true" has a known bug in asp.net 2.0, see here.

Also, the correct syntax is maintainScrollPositionOnPostback. (lowercase m)

I used the maintainScrollPositionOnPostback but have many problems in IE, then I use the asp.net AJAX Control Toolkit UpdatePanel, it solves the problem (the page don't scroll to the top) and save some bandwidth.

EDIT:

I think I understand your problem, it's mantain the focus on the element, it can be done using some javascripts workarounds, se here.

Hope that helps.

Gustavo F
  • 2,071
  • 13
  • 23
  • Hi, thanks for the answer. I have just edited my question, I should have posted earlier. I have tried both in an Ajax updatePanel and without the updatePanel, both give the same symptoms. I am also using .Net 4.0. I have just tried replacing M with m as you suggested but the scrolling still happens. – Skintkingle Jan 16 '12 at 12:57
  • I have followed these steps. This is exactly what i needed. Big fat sloppy kudos to you! – Skintkingle Jan 16 '12 at 14:25
  • I know this is an old post, but it should be noted that IntelliSense says that "MaintainScrollPositionOnPostback" capital "M" is the correct spelling. – htm11h Feb 20 '14 at 17:10
  • 1
    i had to remove the "element.Focus()" from my code behind. I had set elements to .Focus() and seems like it overriding the MaintainScrollPosition. – spacemonkey Nov 26 '19 at 14:06