Click to See Complete Forum and Search --> : moving listbox vertical scrollbar during postback


sharon_mccarty
September 3rd, 2004, 03:53 PM
Hi everyone,

I have a listbox and I have set the postback property for the listbox to be true.

I have many items in the listbox. When I use the vertical scrollbar to scroll down and select an item from the list (it causes the listbox to do an automatic postback to the server).

The problem is that the vertical scrollbar moves back up when I scroll all the way to the bottom of the list and select the bottom items. I guess it's just trying to "refresh" itself when it does a postback by having the scrollbar go back up.

Is there a way to make the scroll bar stay in the same position after you select on items in the listbox?

Thanks!

Sharon

MRutledge
September 8th, 2004, 06:06 PM
Sharon Try this turning on Smart Navigation and see if that works. If it doesn't try the following:

Add this after the <form> tag:

<input type="hidden" name="__SCROLLPOS" value="" />


Add this code to your base page in the PreRender method so the attributes are
added to the HTML Head tag whenever a form with that hidden field is posted. This is basically pseudo code. You need to add your listbox control for the .Attributes part of it.


if(Request("__SCROLLPOS") != null && Request("__SCROLLPOS") 1= String.Empty)
{
int pos = Convert.ToInt32(Request("__SCROLLPOS")).Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value = Body.scrollTop;"
.Attributes("onload") = "javascript:Body.scrollTop=" & pos & ";"
}
else
{
.Attributes("onscroll") = "javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value = Body.scrollTop;"
}


I hope this gets you in the right direction.