473,472 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to remember asp:listbox's scrollbar position

hi,
I had an asp:listbox, and everytime i click item inside, the bar
automatically go to the top, is there any way to keep the scroll position?
I turn on the smartNavigation, it still doesn't work.

Thanks ahead.
Nov 18 '05 #1
1 9844
Hi Daniel,

From your description, you're using an ASP.NET ListBox in your web page
and set it as AutoPostBack, and since the page is contains large content,
when you select in the ListBox, you need to scroll the page down. However,
you find when the listbox's index changed and post back, the page will
reset to to top rather than keep the origianl scroll position, yes?

I'm not sure whether there're anyother particular elements or script code
in your page, but based on my local test, it seems that the
"SmartNavigation" can do this task, I just turn on the smartnavigation and
when the listbox autopostback, the page will remain the last scroll
poistion. Would you please have a further test?

In addition, there is another means I think can keep the scroll poistion,
since it is the ListBox which cause the post back, we can register a
certain client script which will set the focus back to the ListBox after
the page return back to the client side again after the post back. Here is
a demo page I've made, you can have a view if you have anything unclear:

==============aspx page====================
<HTML>
<HEAD>
<title>ListBox</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function setFocus(id)
{
var elm = document.getElementById(id);
elm.focus();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>dddddddddddddddddddddddddddddddddddddddddddddd ddddddd</td>
</tr>
<tr>
<td>
<asp:ListBox id="ListBox1" runat="server" Height="142px"
Width="136px" AutoPostBack="True">
<asp:ListItem Value="aaa">aaa</asp:ListItem>
<asp:ListItem Value="bbb">bbb</asp:ListItem>
<asp:ListItem Value="ccc">ccc</asp:ListItem>
<asp:ListItem Value="ddd">ddd</asp:ListItem>
<asp:ListItem Value="eee">eee</asp:ListItem>
<asp:ListItem Value="fff">fff</asp:ListItem>
<asp:ListItem Value="ggg">ggg</asp:ListItem>
<asp:ListItem Value="hhh">hhh</asp:ListItem>
<asp:ListItem Value="iii">iii</asp:ListItem>
</asp:ListBox></td>
</tr>
</table>
</form>
</body>
</HTML>

===========code behind page class===========
namespace FormAuthApp.controls
{
/// <summary>
/// Summary description for ListBox.
/// </summary>
public class ListBox : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox ListBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ListBox1.SelectedIndexChanged += new
System.EventHandler(this.ListBox1_SelectedIndexCha nged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void ListBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
string script = "<script
language='javascript'>setFocus('{0}');</script>";
script = string.Format(script,ListBox1.ClientID);

Page.RegisterStartupScript("script",script);

Response.Write("<br>SelectedIndex: " + ListBox1.SelectedIndex);
}
}
=======================================

Also, if you have any other ideas, please also feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2

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

Similar topics

0
by: Richard Fennell | last post by:
I am trying to use asp:listbox on a form, when a user selects a row in the asp:listbox a panel is displayed on the centre of the screen with a message, a bit like a model dialog on the form. The...
0
by: John Giblin | last post by:
I have a ListBox within a repeater tag and I am trying to set the selected value. I tried the following without success. I was also tryng to make a method for the selectedindex but I do not know...
1
by: Ray Valenti | last post by:
I have a ASP listbox that I am trying to populate with two fields, one for display (Category) and one to store (ID) as the selected item. I can successfully populate and view the list. How ever...
2
by: Dan Nash | last post by:
Hi again! Right, okay... im now trying to get the value of an <asp:TextBox> control. so I have on my ASPX page... <asp:ListBox id="results" runat="server"></asp:ListBox> <asp:TextBox...
2
by: Simon Prince | last post by:
Help I have a ASP:Listbox on a form. My page Adds items to this this via Client-Side Script only. Such as... var vObj_TargetElement =...
3
by: Ryan Taylor | last post by:
Hello. I have an application where I need the user to be able to add items to a listbox. I've implemented this via javascript. The listbox is an <asp:ListBox>. However, when the user submits the...
5
by: Chris Kettenbach | last post by:
Good morning, Does anyone happen to know if there's a way to make an array of the selected items in an asp:ListBox? I know you can loop through and check the selected property, my question is how...
2
by: Mark Rae | last post by:
Hi, Looking for some advice again... Imagine two ListBox controls denoting something like students and team membership e.g. many students can be members of many teams (e.g. the hockey team,...
7
by: mikeh3275 | last post by:
I'm creating a .net program that uploads images to the FTP server. A blank listbox is populated dynamically on the client side from the value of the html input file widget. There is also a...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.