473,322 Members | 1,307 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,322 software developers and data experts.

Maintain scroll position in ASP.Net

I am trying to convert the VB.Net code example povided by
http://authors.aspalliance.com/JimRo...ScrollPos.aspx
into C# (ASP.Net)without success. No errors are thrown in the VB code
provided on the website.
Once I have this example running correctly, I will need to use the
concept in a more complex project. The code I am using involves an
webform and an htc file.

The code for ScrollPos.htc (which is located in a folder within the
project called 'Includes'):

-----------------------------------------------------------------
<PUBLIC:ATTACH EVENT=ondocumentready ONEVENT="elementLoad()" />
<PUBLIC:PROPERTY NAME="scrollPos" />
<PUBLIC:PROPERTY NAME="persistID" />

// DHTML behavior for scrollable DIV
// (or other scrollable element)
//
// allows element to maintain scroll position within
// the DIV across postbacks.

<script language="javascript">
function elementLoad() {
element.scrollTop = scrollPos;
element.attachEvent("onscroll", saveScroll);
}

function saveScroll() {
element.document.all[persistID].value =
event.srcElement.scrollTop;
}
</script>

---------------------------------

The HTML code for the ASP file is:

<%@ Page language="c#" Codebehind="MaintainScrollDemo.aspx.cs"
AutoEventWireup="false" Inherits="TestC.MaintainScrollDemo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MaintainScrollDemo</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">
<LINK href="../Styles.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<P align="center"><A href="MaintainScrollPos.aspx">&lt;&nbsp; Back
to article</A>
</P>
<P align="left">Here is a demonstration of retaining scroll
position in a
&lt;DIV&gt; element that is being used to add scroll bars to a
DataGrid.&nbsp;
Try scrolling&nbsp;both grids a few rows, then make the form post
back by
clicking any of the Select buttons in either grid.
</P>
<H1 align="center">This Grid Won't Retain Scroll Position</H1>
<blockquote style="TEXT-ALIGN: center">
<DIV style="OVERFLOW: auto; WIDTH: 400px; HEIGHT:
120px"><asp:datagrid id="dgOne" width="100%" BorderWidth="1px"
GridLines="Vertical" CellPadding="4" BackColor="White"
ForeColor="Black" BorderStyle="None" BorderColor="#DEDFDE"
Runat="server">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#F7F7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Select" ButtonType="PushButton"
CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:datagrid></DIV>
</blockquote>
<H1 align="center">This Grid Will Retain Scroll Position</H1>
<blockquote style="TEXT-ALIGN: center">
<% string scrollPosURL = "../Includes/ScrollPos.htc"; %>
<DIV persistID="<%= saveScrollPos.UniqueID %>"
scrollPOS="<%= saveScrollPos.value %>" style ="BEHAVIOR:
url(<%= ResolveURL(scrollPosURL);%>);WIDTH: 400px;HEIGHT: 120px"
persistID="<%= saveScrollPos.UniqueID %>" scrollPOS="<%=
saveScrollPos.value %>">
<INPUT id="saveScrollPos" type="hidden">&nbsp;
<asp:datagrid id="dgTwo" width="100%" BorderWidth="1px"
GridLines="Vertical" CellPadding="4" BackColor="White"
ForeColor="Black" BorderStyle="None" BorderColor="#DEDFDE"
Runat="server">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#F7F7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Select" ButtonType="PushButton"
CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:datagrid></DIV>
</blockquote>
</form>
</body>
</HTML>
-------------------------------------
The code behind for this page is:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TestC
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class MaintainScrollDemo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgOne;
protected System.Web.UI.WebControls.DataGrid dgTwo;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
this.BindLists();
}
}

private void BindLists()
{

//ArrayList[] winelist = new ArrayList[11];
//string [] winelist ;

string [] winelist = new string[12]{"Chateau Lafite Rothschild,
1959",
"Chateau Mouton Rothschild, 1945",
"Maddog 'da Ripper, yesterday",
"Penfolds Grange, 1981",
"Patricia Green Cellars, Estate Pinot Noir, 2000",
"Owen Roe Pinot Gris, 2001",
"d'Arenberg Dead Arm Shiraz, 1978",
"Adelsheim Chardonnay, Elizabeth's Reserve, 1989",
"Screaming Eagle, 1998",
"Far Niente Chardonnay, 2002, 'why pay less?'",
"Vieux Telegraphe CnDP, 1989",
"Whennler Sonnenur Auselese, J.J.Prum, 1978"};

this.dgOne.DataSource = winelist;
this.dgOne.DataBind();
this.dgTwo.DataSource = winelist;
this.dgTwo.DataBind();
}
#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.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
----------------------------------------------

Hopefully someone is able to point a frustrated C# ASP.Net newbie in
the right direction.

Thanks in anticipation

Grant
Nov 22 '05 #1
4 7820
Ok, so what problem are you having exactly? ...
Nov 22 '05 #2
Ok, so what problem are you having exactly? ...
Nov 22 '05 #3
Hi Jon
Thanks for your reply.
The compiler generated message displayed when I try to run the app is as
below:

----------------------------------------

Compiler Error Message: CS1026: ) expected

Source Error:
Line 37: <blockquote style="TEXT-ALIGN: center">
Line 38: <% string scrollPosURL = "../Includes/ScrollPos.htc"; %>
Line 39: <DIV persistID="<% saveScrollPos.UniqueID; %>"
scrollPos="<%= saveScrollPos.value; %>" style ="BEHAVIOR: url(<%=
ResolveURL(scrollPosURL);%>);OVERFLOW: auto;WIDTH: 400px;HEIGHT: 120px"

Line 40: <input id="saveScrollPos" type="hidden"
name="saveScrollPos" runat="server">
Line 41: <asp:datagrid id="dgTwo" width="100%" BorderWidth="1px"
GridLines="Vertical" CellPadding="4" BackColor="White"

--------------------------------

I have played around with the HTML syntax as best as I can but the
'hint' - expected ')' has not helped me so far. Drats!

I have also set Alerts in the htc file (code as per Google posting). So
I know when that file is hit.

Possibly there is something in required in the C# code behind that is
not required in the VB.Net example.

Thanks for your time.

Cheers

Grant

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #4
Hi Jon
Thanks for your reply.
The compiler generated message displayed when I try to run the app is as
below:

----------------------------------------

Compiler Error Message: CS1026: ) expected

Source Error:
Line 37: <blockquote style="TEXT-ALIGN: center">
Line 38: <% string scrollPosURL = "../Includes/ScrollPos.htc"; %>
Line 39: <DIV persistID="<% saveScrollPos.UniqueID; %>"
scrollPos="<%= saveScrollPos.value; %>" style ="BEHAVIOR: url(<%=
ResolveURL(scrollPosURL);%>);OVERFLOW: auto;WIDTH: 400px;HEIGHT: 120px"

Line 40: <input id="saveScrollPos" type="hidden"
name="saveScrollPos" runat="server">
Line 41: <asp:datagrid id="dgTwo" width="100%" BorderWidth="1px"
GridLines="Vertical" CellPadding="4" BackColor="White"

--------------------------------

I have played around with the HTML syntax as best as I can but the
'hint' - expected ')' has not helped me so far. Drats!

I have also set Alerts in the htc file (code as per Google posting). So
I know when that file is hit.

Possibly there is something in required in the C# code behind that is
not required in the VB.Net example.

Thanks for your time.

Cheers

Grant

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #5

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

Similar topics

2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
8
by: ed | last post by:
Does anyone know if ASP.NET 2.0 is going to incorporate "maintain scroll position on postback" in non-IE browsers like Firefox? This seems like an often requested feature on these newsgroups...
4
by: ojorus | last post by:
Hi! I just wonder how I can save a page's scroll position with javascript. (i'm not a javascript developer) I have a PHP-page with two columns; the left contains a lot of thumbnails, and the right...
1
by: Smith John | last post by:
I am developing web based application using ASP.Net. When the user clicks on the last button in the screen(scrolled down screen), screen postback happens, and display at the start of the page. 1....
1
by: santosh singh | last post by:
Hi, I have one .aspx file which is generating whole page dynamically by taking all the HTML tags from SQL SERVER 2000 database . This .aspx is also containing one user control ( which contains two...
0
by: ranabhavin2 | last post by:
Hi , I have made chat application in asp.net using atlas. It is database chat. So, every 1 minutes page is going to refresh and fetch data from database. All the data of chatting I m...
0
by: Keithb | last post by:
The maintain scroll position on postback feature works as expected with my site running under localhost on the development machine. When the files are posted to an IIS 6.0 web server running on a...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.