Mark Roberts
1/24/2003 1:31:00 PM
Very sad, I know, replying to my own message, but I developed one
possible solution (not using custom server controls, but javascript) -
just to show I mean business :)
Save the following into 'SaveScrollPosition.js':
var __oScrollPos;
window.onload=InitScrollPos;
function InitScrollPos(){
__oScrollPos = document.all['__SCROLLPOSITIONS'];
if (__oScrollPos!=undefined){
LoadScrollPos();
basePostBack = __doPostBack;
__doPostBack = MyPostBack;
document.forms[0].onsubmit = MyPostBackFrm;
}
}
function MyPostBackFrm(){
SaveScrollPos();
document.forms[0].submit();
}
function MyPostBack(eventTarget, eventArgument){
SaveScrollPos();
basePostBack(eventTarget, eventArgument);
}
function SaveScrollPos(){
var oNodeList = document.body.getElementsByTagName('DIV');
var sPos = '';
for (i=0;i<oNodeList.length;i++){
oDiv = oNodeList[i];
if (oDiv.scrollTop>0) {
if (sPos.length>0) sPos = sPos + ',';
sPos=sPos + oDiv.id + ':' + oDiv.scrollTop;
}
}
__oScrollPos.value=sPos;
}
function LoadScrollPos(){
if (__oScrollPos.value=='') return;
var sPos = new String();
sPos = __oScrollPos.value
sItems = sPos.split(',');
for (i=0;i<sItems.length;i++){
var sItem = new String();
sItem = sItems[i];
var iSplit = sItem.indexOf(":",0);
sDiv = sItem.substring(0,iSplit);
sPos = sItem.substring(iSplit+1,sItem.length);
try {
document.all[sDiv].scrollTop=sPos;
} catch(e) { }
}
}
Then add the following to the Page_Load event (must be run for each
and every postback):
this.RegisterStartupScript("ScrollPositions","<script
language=javascript src='SaveScrollPosition.js'></script>");
this.RegisterHiddenField("__SCROLLPOSITIONS",Request["__SCROLLPOSITIONS"]);
Then all you have to do is drop one or more grid layout controls onto
the form, set it's overflow to scrollbarsifneeded (or
scrollbarsalways), and *give it an ID* And hey presto, the scroll
position of all divs is maintained. I guess this could be extended to
IFRAMES (yuk).
Still would like to know how I can extend the functionality of a
Panel/Grid Layout Panel !!!!!
Mark.
markalroberts@hotmail.com (Mark Roberts) wrote in message news:<3ca15ed0.0301231628.20d23e1d@posting.google.com>...
> Hi
>
> Scenario:
> I'm trying to use either the HTML Grid Layout Panel OR the Web Control
> 'Panel' with ms_positioning="GridLayout" to create a custom control
>
> Reason:
> I'm finding that I'm using the Grid Layout Panel frequently, and
> setting the overflow property to 'Scrollbars When Needed' - very
> useful for areas of the page that are dynamic in size. The only
> problem with this is that whenever a postback occurs, the position on
> the scrollbar is reset. Smart navigation doesn't seem quite smart
> enough to remember this position, and it can be quite a pain for users
> to have to scroll down again.
>
> Now, what I'd like to do is to create a webcontrol that inherits from
> this base control, and adds the functionality necessary to 'remember'
> the scrollposition. My intention is to emmit an additional hidden
> field, and some client-side script that handles the onscroll event for
> the div. This will save the 'scrolltop' property of the div into the
> hidden field, which will be posted back to the server. The server-side
> of the custom control will pick up this value and emit client-side
> script to re-scroll to the previous position.
>
> I think it *might* work, but I'm having problems in the following
> areas...
>
>
> The problems:
>
> 1) How can I emit the 'ms_positioning="GridLayout"' attribute in the
> webcontrol definition (at the moment, the control acts like a Flow
> layout panel)
> 2) How can I emit the 'position:absolute' style attribute into the
> webcontrol definition - currently the control displays inline, despite
> the page being grid-layout.
> 3) How can I ensure that all the properties for the Grid Layout Panel
> are available for the custom control
>
> I've currently tried inheriting from
> System.Web.UI.HtmlControls.HtmlContainerControl and
> System.Web.UI.WebControls.Panel, and the problems are the same for
> both.
>
>
>
> Thanks hugely to anyone with some guidance for me - it will be most
> appreciated!
>
> Mark.