473,761 Members | 4,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheriting behavior file

Hi,
I have a behavior file called ScrollPos.htc, which is supposed to
maintain the scroll position of a datagrid within a div tag.

In my html I have

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="Maint ainScrollDemo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Maintain ScrollDemo</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1"/>
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1"/>
<meta name="vs_defaul tClientScript" content="JavaSc ript"/>
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5"/>
<link href="../Styles.css" type="text/css" rel="stylesheet "/>

</head>
<body MS_POSITIONING= "FlowLayout ">
<form id="form1" runat="server">
<p align="center">
<a href="Default.a spx"><
Back to article</a</p>
<p align="left">
Here is a demonstration of retaining scroll position in a
<DIVelement that is being used to add scroll bars to a DataGrid.
Try scrolling both grids a few rows, then make the form post back by
clicking any of the Select buttons in either grid. </p>
</blockquote>

<h1 align="center"> This Grid Will Retain Scroll Position</h1>
<blockquote style="TEXT-ALIGN: center">
<% string scrollPosURL = "../ScrollPos.htc"; %>
<div persistID="<%= saveScrollPos.U niqueID %>" scrollPOS="<%=
saveScrollPos.V alue %>"
style="OVERFLOW : auto; WIDTH: 400px; HEIGHT: 120px; behavior:
url(ScrollPos.h tc);">

<input id="saveScrollP os" type="hidden" runat="server" name="saveScrol lPos"/>

<asp:DataGrid id="dgTwo" runat="server" BorderColor="#D EDFDE"
BorderStyle="No ne" ForeColor="Blac k"
BackColor="Whit e" CellPadding="4" GridLines="Vert ical"
BorderWidth="1p x" width="100%">

<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>
Here is my htc file in the same directory as the web form

<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>
It just seems to get ignored and the datagrid loses its scroll position
after each postback, any idea whats going on???

Thanx in advance
Robert


Jun 27 '08 #1
1 1307
"Robert Smith" <Ro*********@di scussions.micro soft.comwrote in message
news:DB******** *************** ***********@mic rosoft.com...
Hi,
I have a behavior file called ScrollPos.htc, which is supposed to
maintain the scroll position of a datagrid within a div tag.

In my html I have

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="Maint ainScrollDemo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Maintain ScrollDemo</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1"/>
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1"/>
<meta name="vs_defaul tClientScript" content="JavaSc ript"/>
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5"/>
<link href="../Styles.css" type="text/css" rel="stylesheet "/>

</head>
<body MS_POSITIONING= "FlowLayout ">
<form id="form1" runat="server">
<p align="center">
<a href="Default.a spx"><
Back to article</a</p>
<p align="left">
Here is a demonstration of retaining scroll position in a
<DIVelement that is being used to add scroll bars to a DataGrid.
Try scrolling both grids a few rows, then make the form post back by
clicking any of the Select buttons in either grid. </p>
</blockquote>

<h1 align="center"> This Grid Will Retain Scroll Position</h1>
<blockquote style="TEXT-ALIGN: center">
<% string scrollPosURL = "../ScrollPos.htc"; %>
<div persistID="<%= saveScrollPos.U niqueID %>" scrollPOS="<%=
saveScrollPos.V alue %>"
style="OVERFLOW : auto; WIDTH: 400px; HEIGHT: 120px; behavior:
url(ScrollPos.h tc);">

<input id="saveScrollP os" type="hidden" runat="server"
name="saveScrol lPos"/>
>
<asp:DataGrid id="dgTwo" runat="server" BorderColor="#D EDFDE"
BorderStyle="No ne" ForeColor="Blac k"
BackColor="Whit e" CellPadding="4" GridLines="Vert ical"
BorderWidth="1p x" width="100%">

<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>
Here is my htc file in the same directory as the web form

<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>
It just seems to get ignored and the datagrid loses its scroll position
after each postback, any idea whats going on???
HTCs are arcane, ancient and very IE-centric. I wouldn't avoid them.

Use something like this (warning untested):-

//ScrollPos.js
function ScrollPos(elem)
{
var saveId = elem.getAttribu te("saveScrollI D")
var scrollTop = document.getEle ment(saveID).va lue
elem.scrollTop = scrollTop
elem.onscroll = function()
{
document.getEle ment(saveID).va lue = this.scrollTop
}
elem = null;
}

<script type="text/javascript" src="ScrollPost .js"></script>
<script type="text/javascript">

function body_onload()
{
window.setTimeo ut(handleLoad, 100)

function handleLoad()
{
new ScrollPos(docum ent.getElementB yId('idOfDiv')) ;
}
}

</script>
<body onload="body_on load()"
--
Anthony Jones - MVP ASP/ASP.NET
Jun 27 '08 #2

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

Similar topics

15
1712
by: JustSomeGuy | last post by:
this doesn't want to compile.... class image : public std::list<element> { element getElement(key k) const { image::iterator iter; for (iter=begin(); iter != end(); ++iter) { element &elem(*iter);
5
1508
by: Azumanga | last post by:
I am trying to define a series of iterators for a container I am building, and as forward, bidirectional and random access iterators are very similar I thought it would be handy to put them into a heirachy, much like the code below: struct MyForwardIterator { typedef forward_iterator_tag iterator_category; // forward iterator functions };
29
5898
by: shaun roe | last post by:
I want something which is very like a bitset<64> but with a couple of extra functions: set/get the two 32 bit words, and conversion to unsigned long long. I can do this easily by inheriting from bitset<64>, but I know that STL has no virtual destructor. Can I get around this by calling the baseclass destructor explicitly in my derived class? Is there another way to get all of the bitset<64> functionality without rewriting a lot of...
2
2563
by: aundro | last post by:
Hello, I've recently been developping a google-maps-like api. Firstly, I started development under Firefox, but I now need to run it under Internet Explorer, and I'm running into a little bit of trouble.. With firefox, a "MapView" object actually subclasses a HTMLDivElement, as follows:
11
2168
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain methods, such as public void Add(MyClass c). How can I enforce the same behavior (of requiring to implement a member with a new return type in an inherited class) in the master class (similar to the CollectionBase)? I have a class called...
24
2957
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
2
2534
by: ThunderMusic | last post by:
Hi, Maybe there is another way of doing this, but here's my problem... I have my web site where I have a master page to have a common layout and a common behavior on all my pages (that's what it's intended for)... But now here comes the time where some pages need some processing (like, is the user logged? and those kind of things)... If it was only on 1 or 2 pages, I'd says, i'll put it directly in the code and case closed, but there...
2
1701
by: snorble | last post by:
I started creating a simple "bits" class, intended to act like a array of bits. This was my initial idea, basically just overriding the string representation to display the bitmask (so far): class bits(long): def __str__ (self): s = '' if self == 0L: s += '-' else:
4
1699
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 : public virtual base
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
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
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
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
7332
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
6609
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
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2752
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.