Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client Callbacks

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

I am trying to implement a client callback. Ultimately what I am trying to do is remember the scroll position of a scrollable div on postback.

When the user selects a tree node, I run some javascript to get the node's value. I then pass this value to a server function that finds a panel with that same ID and returns its ClientID. This panel is nested within a scrollable panel. Then in my client callback function, I scroll to that panel so that it is visible inside of its parent, and I set a hidden field value to remember the new scroll position. I then have some javascript that I registered in my code-behind using RegisterStartupScript that calls another javascript function to set the scroll position of the div using the hidden field value. The problem is that my hidden field value is being reset and I can't figure out why.

Here's the relevant Javascript:

Code:
function OnTreeClick() {

var src = window.event.srcElement;

var nodeClick = src.tagName.toLowerCase() == "a";

var context = "";

if (nodeClick) {

var componentText = src.innerText;

var componentId = GetNodeValue(src);

CallServer(componentId, context);

}

}

//This is the client callback function.

function scrollTo(component) {

if (component != null) {

var element = document.getElementById(component);

element.scrollIntoView(true);

setScroll();

}

}

function setScroll(val) {

document.getElementById('<%= scrollPos.ClientID %>').value = document.getElementById('<%= pnlLayout.ClientID %>').scrollTop;

}

//And the javascript to set the scroll position of the div. However, the hidden field value is no longer set.

function scrollTo2() {

document.getElementById('<%= pnlLayout.ClientID %>').scrollTop = document.getElementById('<%= scrollPos.ClientID %>').value;

}

//Hidden field to store the scroll position.

<asp:HiddenField ID="scrollPos" runat="server" />

I only ever set the value of the hidden field to 0 on the first page load. After that, it is only changed in javascript. It does change the value successfully in setScroll, but by the time scrollTo2 executes, the value has been lost.

Can anybody help?

Thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top