473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ASP.NET ListBox, post back and focus of selected items

Hi,

Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).

I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)

Any way to fix this!

Thanks.

May 14 '07 #1
6 16378
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.

"probashi" wrote:
Hi,

Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).

I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)

Any way to fix this!

Thanks.

May 15 '07 #2
Unfortunately it does not help.

Looks like custom JavaScript will be my last option.

Thanks

On May 15, 2:43 am, Siva M <shiva...@online.excite.comwrote:
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.

"probashi" wrote:
Hi,
Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).
I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)
Any way to fix this!
Thanks.- Hide quoted text -

- Show quoted text -

May 15 '07 #3
probashi,

on page load event you could do something like the following to ensure the
selected item is visible:
<script type="text/javascript">
var lst = document.getElementById('<%= myListBox.ClientID %>';
if (lst && lst.selectedIndex -1){
lst.focus();
lst.selectedIndex = lst.selectedIndex;
}
</script>

Hope it is not too late for you

"probashi" wrote:
Unfortunately it does not help.

Looks like custom JavaScript will be my last option.

Thanks

On May 15, 2:43 am, Siva M <shiva...@online.excite.comwrote:
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.

"probashi" wrote:
Hi,
Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).
I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)
Any way to fix this!
Thanks.- Hide quoted text -
- Show quoted text -


May 18 '07 #4
Looks like I cannot solve this with JavaScript either.

Here is the code I tried.
<script type= "text/javascript">
var lst = document.getElementById("list1");
var options = lst.options;
var option;
var i;
for(i = 0; i < options.length; i++)
{

if(options[i].selected)
{

options[i].focus();
}
}
</script>

On May 15, 9:27 am, probashi <proba...@hotmail.comwrote:
Unfortunately it does not help.

Looks like custom JavaScript will be my last option.

Thanks

On May 15, 2:43 am, Siva M <shiva...@online.excite.comwrote:
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.
"probashi" wrote:
Hi,
Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).
I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)
Any way to fix this!
Thanks.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 18 '07 #5
probashi,

take a look at my previous response - I have tested it before posting - it
does select the correct item on postback - you need to focus the list and
then select the selected item again.

"probashi" wrote:
Looks like I cannot solve this with JavaScript either.

Here is the code I tried.
<script type= "text/javascript">
var lst = document.getElementById("list1");
var options = lst.options;
var option;
var i;
for(i = 0; i < options.length; i++)
{

if(options[i].selected)
{

options[i].focus();
}
}
</script>

On May 15, 9:27 am, probashi <proba...@hotmail.comwrote:
Unfortunately it does not help.

Looks like custom JavaScript will be my last option.

Thanks

On May 15, 2:43 am, Siva M <shiva...@online.excite.comwrote:
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.
"probashi" wrote:
Hi,
Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).
I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)
Any way to fix this!
Thanks.- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -


May 21 '07 #6
I am sorry for not describing the issue properly.

This issue exists only for multi-select list box.

The code you sent does not work for multi-select list box. It makes
the selected item visible but wipes out all the other selections.

Thanks.

On May 18, 12:59 am, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
probashi,

on page load event you could do something like the following to ensure the
selected item is visible:
<script type="text/javascript">
var lst = document.getElementById('<%= myListBox.ClientID %>';
if (lst && lst.selectedIndex -1){
lst.focus();
lst.selectedIndex = lst.selectedIndex;}

</script>

Hope it is not too late for you

"probashi" wrote:
Unfortunately it does not help.
Looks like custom JavaScript will be my last option.
Thanks
On May 15, 2:43 am, Siva M <shiva...@online.excite.comwrote:
See if setting MaintainScrollPositionOnPostback="true" for the @Page attibute
helps.
"probashi" wrote:
Hi,
Issue: After post back selected item of a list box is getting out of
focus (when it contains more items than it's size).
I have a List Box in an ASPX page. I select an item from the ListBox
and after post back the item is still selected but it is not focused
(i.e. I have to scroll down to see the selected item)
Any way to fix this!
Thanks.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Irene | last post by:
I'm developing a Web application where a user selects from a listbox which can have many items. The initial display only shows about 10 items. After a postback, the listbox is automatically...
9
by: Alpha | last post by:
Hi, How can I set all the items in a listbox to be selected? I can't find a property or mehtod to do it so I thought I'll try using setselected method but I need to find out how many items are in...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
10
by: Adam Clauss | last post by:
I have a page containing a list box. This list may contain duplicate items - in which the ORDER is important. ex: a b b a is significant as compared to: b
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
7
by: Lit | last post by:
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...
4
by: bogdan | last post by:
Hi, I have two listboxes on a page and need to move items between them - using buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net? I'd like to avoid hitting the server on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.