Listbox vertical scroll position capture

L

Lit

Hi,

How can I capture the vertical scroll bar position for a Listbox.

I have a Listbox of 100 items + when I click on it I post back remove the
item selected.

After returning to the client browser the list box scroll position is at the
top.

I want it to be remain in the Proximity of where it was before.

Can I capture the vertical scroll bar position of a ListBox in JavaScript
and set it?

Thank you,

Lit
 
S

Steve

I reproduced what you're getting, and fixed it using this code:


Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim x As Integer = ListBox1.SelectedIndex
ListBox1.Items.Remove(ListBox1.SelectedItem)
ListBox1.SelectedIndex = x + 1
End Sub


Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
L

Lit

Steve,

Here is the problem:

After post back I don't want the selected Index set because I can no longer
select that Item by just clicking on it to cause a post back
I have an onSelectedIndexChanged event that fires when a list item is
selected.

How do I scroll as if I am a user scrolling without selecting anything.

( x below can be index out of bounds if last or listbox is empty )

Any JavaScript tricks, any other Ideas you can think off.

Thank you,


Lit
 
S

Steve

I understand. You're removing the item at index "x", so you can't select
it anymore. If you set the SelectedIndex to x+1 (or even x-1), that will
cause the item after (or before) to be the currently selected item. The
auto-postback still works, the item is still deleted, and the listbox
scroll position is still preserved.

You can try to capture that via Javascript, but in this case, it's not
needed, and just adds to the complexity. Besides, if you're using a
postback, you're already making the round-trip to the server, so you
might as well do everything there, right?



Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
L

Lit

Hi Steve,

I am using AJAX so my post back is not the ALL-Page Postback.
I select from the "Source" list box, add the item to a "Destination" list
box and remove the item that was selected from the "Source" listbox.
Now if I ( x+1, or x-1 ) I can NO longer select that selected item to
trigger a postback, remember I am not clicking on a button.
The selected index change event does not fire when something is already been
selected.

Also if I change to x+1 or x-1 the event is fired on the server side, I
think so I have to disable the event before x+1 or x-1 then enable it
again.

How can I capture the list box vertical scroll position in JavaScript and
set it without selecting anything in the listbox
Is this doable for a listbox?

Does <Select Selected > Fire An event, if not that is good. if yes that
is not the behavior I want.

Thanks for taking the time to thing this with me.

Lit
 
S

Steve

Ahhh, AJAX. Okay, so you've got to preserve the scroll location without
re-selecting any item in the listbox. I don't think I've ever seen any
Javascript that can do that, but I'm not a Javascript guru.

Try reposting this in the MS JScript newsgroups. I know JScript isn't
*exactly* javascript, but I don't think MS has an ASP.NET Ajax newsgroup
yet.
 
L

Lit

Steve,

thank you for your input, I will have to research this or come up with
other UI

Lit
 
L

Lit

looking for good JavaScript website, groups out here???? that might help in
this problem?

Thank you,

Lit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top