473,386 Members | 1,706 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,386 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 7826
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.