inheriting behavior file

inheriting behavior file

am 13.04.2008 12:16:00 von RobertSmith

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="Default.aspx.cs"
Inherits="MaintainScrollDemo" %>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



MaintainScrollDemo



content="http://schemas.microsoft.com/intellisense/ie5"/>






<
Back to article



Here is a demonstration of retaining scroll position in a

element 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.




This Grid Will Retain Scroll Position



<% string scrollPosURL = "../ScrollPos.htc";%>
style="OVERFLOW: auto; WIDTH: 400px; HEIGHT: 120px; behavior:
url(ScrollPos.htc);">



BorderStyle="None" ForeColor="Black"
BackColor="White" CellPadding="4" GridLines="Vertical"
BorderWidth="1px" width="100%">
















CommandName="Select">


Mode="NumericPages">








Here is my htc file in the same directory as the web form





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




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

Re: inheriting behavior file

am 13.04.2008 21:12:34 von Anthony Jones

"Robert Smith" wrote in message
news:DB0C855E-85C2-4A6B-9287-FDC4182B8AF5@microsoft.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="Default.aspx.cs"
> Inherits="MaintainScrollDemo" %>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
>
> MaintainScrollDemo
>
>
>
> > content="http://schemas.microsoft.com/intellisense/ie5"/>
>
>
>
>
>


>


> <
> Back to article


>


> Here is a demonstration of retaining scroll position in a
>

element 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.


>
>
>

This Grid Will Retain Scroll Position


>

> <% string scrollPosURL = "../ScrollPos.htc";%>
>
> style="OVERFLOW: auto; WIDTH: 400px; HEIGHT: 120px; behavior:
> url(ScrollPos.htc);">
>
> name="saveScrollPos"/>
>
> > BorderStyle="None" ForeColor="Black"
> BackColor="White" CellPadding="4" GridLines="Vertical"
> BorderWidth="1px" width="100%">
>
> BackColor="#CE5D5A">
>

>
>
>

>
>
>

>
>
>

>
>
>

>
> > CommandName="Select">
>

>
> > Mode="NumericPages">
>

>

>

>
>
>
>
>
> Here is my htc file in the same directory as the web form
>
>
>
>
>
> // DHTML behavior for scrollable DIV
> // (or other scrollable element)
> //
> // allows element to maintain scroll position within
> // the DIV across postbacks.
>
>
>
>
> 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.getAttribute("saveScrollID")
var scrollTop = document.getElement(saveID).value
elem.scrollTop = scrollTop
elem.onscroll = function()
{
document.getElement(saveID).value = this.scrollTop
}
elem = null;
}





--
Anthony Jones - MVP ASP/ASP.NET