I've implemented a RadListBox which will almost always have more items than will stack vertically, thus there's almost always a scrollbar. For reasons I've explained in other threads, my application requires that a single-click and a double-click cause a server-side postback. That part of the equation has long been built and is working fine.
Where I've run into a problem is the age-old issue of selecting a ListBox item near the bottom, having the postback occur, and then the ListBox item no longer in exactly the same vertical position it was before and often not even visible. I've read several threads in this forum addressing this problem and have come up with this solution of my own:
In the server-side method that handles selecting a listbox item, I added this code:
Which in turns executes this code on the client after the postback is done:
It seems to be working "okay" but I'm just wondering if, in 2012, this is the best/easiest way to solve this problem or whether there's a simpler/better approach?
Thank you,
Robert
Where I've run into a problem is the age-old issue of selecting a ListBox item near the bottom, having the postback occur, and then the ListBox item no longer in exactly the same vertical position it was before and often not even visible. I've read several threads in this forum addressing this problem and have come up with this solution of my own:
In the server-side method that handles selecting a listbox item, I added this code:
Page page = HttpContext.Current.CurrentHandler
as
Page;<br> ScriptManager.RegisterStartupScript(page, page.GetType(), Guid.NewGuid().ToString(),
"setTimeout(function() {scrollIntoView()}, 100);"
,
true
);
Which in turns executes this code on the client after the postback is done:
function
scrollIntoView() {<br>
var
slidingZone = $find($(
'table[id$=_radSlidingZone]'
)[0].id);<br>
var
slidingPane = slidingZone.getPanes()[0];<br>
var
listBox = $find($(
"#"
+ slidingPane.get_id() +
" div[id$=_radListBoxStopes]"
)[0].id);<br><br>
var
item = listBox.get_selectedItem();<br>
if
(item !=
null
)<br> item.scrollIntoView();<br> }
It seems to be working "okay" but I'm just wondering if, in 2012, this is the best/easiest way to solve this problem or whether there's a simpler/better approach?
Thank you,
Robert