473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)withou t 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:ATTAC H EVENT=ondocumen tready ONEVENT="elemen tLoad()" />
<PUBLIC:PROPERT Y NAME="scrollPos " />
<PUBLIC:PROPERT Y NAME="persistID " />

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

<script language="javas cript">
function elementLoad() {
element.scrollT op = scrollPos;
element.attachE vent("onscroll" , saveScroll);
}

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

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

The HTML code for the ASP file is:

<%@ Page language="c#" Codebehind="Mai ntainScrollDemo .aspx.cs"
AutoEventWireup ="false" Inherits="TestC .MaintainScroll Demo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Maintain ScrollDemo</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="C#" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
<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="MaintainS crollPos.aspx"> &lt;&nbsp; Back
to article</A>
</P>
<P align="left">He re 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:dat agrid id="dgOne" width="100%" BorderWidth="1p x"
GridLines="Vert ical" CellPadding="4" BackColor="Whit e"
ForeColor="Blac k" BorderStyle="No ne" BorderColor="#D EDFDE"
Runat="server">
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#CE5 D5A"></SelectedItemSty le>
<AlternatingIte mStyle BackColor="Whit e"></AlternatingItem Style>
<ItemStyle BackColor="#F7F 7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#6B6 96B"></HeaderStyle>
<FooterStyle BackColor="#CCC C99"></FooterStyle>
<Columns>
<asp:ButtonColu mn Text="Select" ButtonType="Pus hButton"
CommandName="Se lect"></asp:ButtonColum n>
</Columns>
<PagerStyle HorizontalAlign ="Right" ForeColor="Blac k"
BackColor="#F7F 7DE" Mode="NumericPa ges"></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.U niqueID %>"
scrollPOS="<%= saveScrollPos.v alue %>" style ="BEHAVIOR:
url(<%= ResolveURL(scro llPosURL);%>);W IDTH: 400px;HEIGHT: 120px"
persistID="<%= saveScrollPos.U niqueID %>" scrollPOS="<%=
saveScrollPos.v alue %>">
<INPUT id="saveScrollP os" type="hidden">& nbsp;
<asp:datagrid id="dgTwo" width="100%" BorderWidth="1p x"
GridLines="Vert ical" CellPadding="4" BackColor="Whit e"
ForeColor="Blac k" BorderStyle="No ne" BorderColor="#D EDFDE"
Runat="server">
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#CE5 D5A"></SelectedItemSty le>
<AlternatingIte mStyle BackColor="Whit e"></AlternatingItem Style>
<ItemStyle BackColor="#F7F 7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#6B6 96B"></HeaderStyle>
<FooterStyle BackColor="#CCC C99"></FooterStyle>
<Columns>
<asp:ButtonColu mn Text="Select" ButtonType="Pus hButton"
CommandName="Se lect"></asp:ButtonColum n>
</Columns>
<PagerStyle HorizontalAlign ="Right" ForeColor="Blac k"
BackColor="#F7F 7DE" Mode="NumericPa ges"></PagerStyle>
</asp:datagrid></DIV>
</blockquote>
</form>
</body>
</HTML>
-------------------------------------
The code behind for this page is:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace TestC
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class MaintainScrollD emo : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid dgOne;
protected System.Web.UI.W ebControls.Data Grid dgTwo;

private void Page_Load(objec t sender, System.EventArg s 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.Data Source = winelist;
this.dgOne.Data Bind();
this.dgTwo.Data Source = winelist;
this.dgTwo.Data Bind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(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 7876
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.U niqueID; %>"
scrollPos="<%= saveScrollPos.v alue; %>" style ="BEHAVIOR: url(<%=
ResolveURL(scro llPosURL);%>);O VERFLOW: auto;WIDTH: 400px;HEIGHT: 120px"

Line 40: <input id="saveScrollP os" type="hidden"
name="saveScrol lPos" runat="server">
Line 41: <asp:datagrid id="dgTwo" width="100%" BorderWidth="1p x"
GridLines="Vert ical" CellPadding="4" BackColor="Whit e"

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

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.U niqueID; %>"
scrollPos="<%= saveScrollPos.v alue; %>" style ="BEHAVIOR: url(<%=
ResolveURL(scro llPosURL);%>);O VERFLOW: auto;WIDTH: 400px;HEIGHT: 120px"

Line 40: <input id="saveScrollP os" type="hidden"
name="saveScrol lPos" runat="server">
Line 41: <asp:datagrid id="dgTwo" width="100%" BorderWidth="1p x"
GridLines="Vert ical" CellPadding="4" BackColor="Whit e"

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

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
1810
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 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...
8
2136
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 since the beta version of .NET. Microsoft heavily advertises it's .NET browser detection advantages, why not make some use of it and hope that Microsoft follows up their words with actions? as well as following up on their agreement from the...
4
3655
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 contain a bigger picture of the thumbnailed selected. The problem is that all these thumbnails (and the big picture) are placed quite far down in the document. (a lot of text is at the top.) What I want is that when a thumbnail is clicked, the...
1
1556
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. How to maintain the scrolled position in the web form. 2. I made the following changes in web.config file. <configuration> <system.web> <pages smartNavigation = "true"/> </system.web>
1
4635
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 dropdownlist box ).On selection of some Text in one dropdownlist box , whole page refreshes because autopostback="true" for dropdownlist box . Now after postback , i want to maintain the scroll position . for this i used following options : ...
0
1708
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 displaying in DIV tag with scroll bar. Problem : when page is refreshed scrollbar position is going to change everytime. So, if user scroll up the divtag and seeing his data then page is refreshed and scrollbar position is again going to change. I...
0
2097
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 Win2k3 box, maintain scroll position on postback simply does not work. The Page_Load event handler in my aspx page has: Page.MaintainScrollPositionOnPostBack = true;
7
5618
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 browser the list box scroll position is at the top.
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
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 we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.