With much prior help from Telerik Support, I've implemented a fairly sophisticated RadListBox which let's the user single-click and double-click. I thought everything was working perfectly until I discovered today that the vertical scrollbar is not maintaining its position between Postbacks. This needs to be fixed.
Here's the pertinent layout code:
And here's the Javascript code that handles the RadListBox:
Please note the last line of code, which calls the "scrollIntoView()" method of the RadListBoxItem. I've stepped through the code and it appears to be running okay. I've also confirmed that the "item" in question is always the correct one. But it's as if "scrollIntoView()" isn't doing anything.
Is there something wrong with my code?
As an ancillary comment, I should mention that I've created a quite extensive function library that uses the AJAX Event Handler functions to maintain the position of any DIV scrollbar that I so identify during initialization. It also works perfectly with your RadTreeView control. But, when I tried using it with the RadListBox, it didn't work. It relies on the fact that the "scrollTop" property of each DIV will range from '0' at its top position to a positive integer at the bottom. So alternatively, if you could tell me how to adapt this code for the RadListBox then I'd also have a solution. In other words, what RadListBox property maintains the scroll position?
Hope you can help!
Robert
Here's the pertinent layout code:
<
asp:Panel
ID
=
"panelMain"
runat
=
"server"
style
=
"border-top: solid 1px #000000; padding-bottom:20px"
>
<
telerik:RadSplitter
ID
=
"radSplitter"
runat
=
"server"
LiveResize
=
"false"
>
<
telerik:RadPane
ID
=
"radPaneLeft"
runat
=
"server"
Scrolling
=
"None"
MinWidth
=
"232"
MaxWidth
=
"272"
>
<
telerik:RadSlidingZone
ID
=
"radSlidingZone"
runat
=
"server"
Width
=
"22"
Height
=
"0"
ClickToOpen
=
"true"
DockedPaneId
=
"radSlidingPane"
>
<
telerik:RadSlidingPane
ID
=
"radSlidingPane"
runat
=
"server"
BackColor
=
"#F0F8FF"
CssClass
=
"slidingPane"
TabView
=
"TextAndImage"
IconUrl
=
"~/Images/hierarchy.gif"
DockOnOpen
=
"true"
OnClientDocked
=
"radSlidingPane_Docked"
OnClientUndocked
=
"radSlidingPane_Undocked"
Width
=
"200"
>
<
telerik:RadListBox
ID
=
"radListBoxMuck"
runat
=
"server"
Width
=
"100%"
Height
=
"100%"
OnClientSelectedIndexChanged
=
"rlbClicked"
OnClientItemDoubleClicked
=
"rlbDoubleClicked"
OnClientContextMenu
=
"rlbContextMenu"
onselectstart
=
"return false;"
OnItemCreated
=
"radListBoxMuck_ItemCreated"
EnableDragAndDrop
=
"false"
>
And here's the Javascript code that handles the RadListBox:
var
rlbClickTimer;
// Required presence for logic to distinguish between single & double-clicks
function
rlbClicked() {
if
(rlbClickTimer) clearTimeout(rlbClickTimer);
rlbClickTimer = setTimeout(
function
() {
// Code in 'rlbContextMenu' causes this method to be called. When a right-click occurs,
// we don't want a PostBack to occur so we're just going to exit quietly.
var
rlbRightClicked = $(
'input[id$=_radListBoxIsRightClicked]'
)[0].id;
var
hidVar = document.getElementById(rlbRightClicked);
if
(hidVar.value ==
'true'
) {
hidVar.value =
''
;
// We successfully intercepted the right-click that got us to here so clear the hidden variable for when a left-click occurs
return
;
}
var
updatePanel = $(
'div[id$=_UpdatePanel1]'
)[0].id;
var
slidingZone = $find($(
'table[id$=_radSlidingZone]'
)[0].id);
var
slidingPane = slidingZone.getPanes()[0];
var
listBox = $find($(
"#"
+ slidingPane.get_id() +
" div[id$=_radListBoxMuck]"
)[0].id);
var
rlbIdxName = $(
'input[id$=_radListBoxIndex]'
)[0].id;
hidVar = document.getElementById(rlbIdxName);
var
rlbIdxVal = hidVar.value;
var
parameters;
if
(rlbIdxVal ==
''
)
parameters =
'radListBoxMuck,'
+ listBox.get_selectedIndex();
else
{
parameters =
'radListBoxMuck,'
+ rlbIdxVal;
hidVar.value =
''
;
}
parameters +=
',1'
;
__doPostBack(updatePanel, parameters);
}, 250);
setTimeout(
function
() { scrollIntoView() }, 400);
}
// Works in conjunction with 'rlbClicked' and handles double-clicking on a RadListBox item.
function
rlbDoubleClicked() {
var
updatePanel = $(
'div[id$=_UpdatePanel1]'
)[0].id;
var
slidingZone = $find($(
'table[id$=_radSlidingZone]'
)[0].id);
var
slidingPane = slidingZone.getPanes()[0];
var
listBox = $find($(
"#"
+ slidingPane.get_id() +
" div[id$=_radListBoxMuck]"
)[0].id);
clearTimeout(rlbClickTimer);
var
parameters =
'radListBoxMuck,'
+ listBox.get_selectedIndex() +
',2'
;
__doPostBack(updatePanel, parameters);
}
// Ensures that the selected item, if there is one, remains visible to the user after a postback.
function
scrollIntoView() {
var
slidingZone = $find($(
'table[id$=_radSlidingZone]'
)[0].id);
var
slidingPane = slidingZone.getPanes()[0];
var
listBox = $find($(
"#"
+ slidingPane.get_id() +
" div[id$=_radListBoxMuck]"
)[0].id);
var
item = listBox.get_selectedItem();
if
(item !=
null
)
item.scrollIntoView();
}
Please note the last line of code, which calls the "scrollIntoView()" method of the RadListBoxItem. I've stepped through the code and it appears to be running okay. I've also confirmed that the "item" in question is always the correct one. But it's as if "scrollIntoView()" isn't doing anything.
Is there something wrong with my code?
As an ancillary comment, I should mention that I've created a quite extensive function library that uses the AJAX Event Handler functions to maintain the position of any DIV scrollbar that I so identify during initialization. It also works perfectly with your RadTreeView control. But, when I tried using it with the RadListBox, it didn't work. It relies on the fact that the "scrollTop" property of each DIV will range from '0' at its top position to a positive integer at the bottom. So alternatively, if you could tell me how to adapt this code for the RadListBox then I'd also have a solution. In other words, what RadListBox property maintains the scroll position?
Hope you can help!
Robert