By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Listbox vertical scroll position capture

P: n/a
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
Aug 21 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
Lit wrote:
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

Aug 21 '07 #2

P: n/a
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

"Steve" <ln********************@gmail.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>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
Lit wrote:
>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
Aug 21 '07 #3

P: n/a
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
Lit wrote:
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

"Steve" <ln********************@gmail.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>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
Lit wrote:
>>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
Aug 21 '07 #4

P: n/a
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

"Steve" <ln********************@gmail.comwrote in message
news:ue**************@TK2MSFTNGP04.phx.gbl...
>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
Lit wrote:
>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

"Steve" <ln********************@gmail.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>>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
Lit wrote:
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

Aug 21 '07 #5

P: n/a
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.


Lit wrote:
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

"Steve" <ln********************@gmail.comwrote in message
news:ue**************@TK2MSFTNGP04.phx.gbl...
>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
Lit wrote:
>>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

"Steve" <ln********************@gmail.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
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
Lit wrote:
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
>

Aug 21 '07 #6

P: n/a
Lit
Steve,

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

Lit
"Steve" <ln********************@gmail.comwrote in message
news:eZ**************@TK2MSFTNGP03.phx.gbl...
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.


Lit wrote:
>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

"Steve" <ln********************@gmail.comwrote in message
news:ue**************@TK2MSFTNGP04.phx.gbl...
>>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
Lit wrote:
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

"Steve" <ln********************@gmail.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
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
>
>
Lit wrote:
>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
>>
Aug 21 '07 #7

P: n/a
Lit
looking for good JavaScript website, groups out here???? that might help in
this problem?

Thank you,

Lit
"Lit" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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


Aug 21 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.