views:

738

answers:

3

This only occurs in Internet Explorer. I have a ListBox which is in an UpdatePanel. The ListBox has around 100 items in it and it shows 15 are visible at a time. They are sorted from 1 to 100. If I scroll to the bottom and select item number 50, item 50 stays selected, but the ListBox jumps back to the top of the List, so it is displaying items 1 thru 15. This only happens in Internet Explorer. If I do this in FireFox, the item selected is still displayed, it just becomes the last visible item in the list meaning item 15. Does anyone know a solution to this and why it is happening?

Thanks, XaiSoft

A: 

Try setting MaintainScrollPositionOnPostBack="true" in your Page directive (<%@ page %>)

Rex M
I just tried it and it is still scrolling back to the top.
Xaisoft
After reading on this, I think it just maintains the scroll position for the page, not the listbox.
Xaisoft
That is the description, though MS support has suggested this handles things like ListBoxes as well... though they may have been lying and/or stupid (has happened before!)
Rex M
A: 

It is happening because when the UpdatePanel updates, it deletes all the existing contents (controls) and recreates them from HTML sent by the server. Control values are included in the update, but things like scroll position are not. The only solution I can think of is to use javascript to record the scroll position before the postback and then restore it after the update panel has finished updating.

CodeMonkey1
Something like this:http://couldbedone.blogspot.com/2007/08/restoring-lost-focus-in-update-panel.html
Xaisoft
Yes, very similar to that.
CodeMonkey1
A: 

This question appears to have been answered in this post:

Maintain scroll position in listboxes in updatepanels, NOT the page

Tod1d