C# – Maintaining Scroll Position and Selected Control on Postback

asp.netcpostback

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!

Best Answer

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.

Related Topic