Wednesday, March 28, 2012

How Do I Reset Scroll Position Inside UpdatePanel?

Hello,

I have a UserControl inside an UpdatePanel. The UserControl contains several DIVs that I show and hide through partial postback. I want the contents of each DIV to be scrolled to the top when I show it. I have tried using the ScriptManager to set focus onto the topmost control of each DIV when I show it, but it doesn't work. I have also tried through javascript to no avail. I know this is kind of the opposite of the behavior that many folks want from AJAX, but I need it for this piece of my application. I have tried searching but all examples are page-centric, not usercontrol-centric and speak to SmartNavigation.

Any help is appreciated.

Brendan

not sure if this would help, but I found something interestingin terms of firing off some js code during a partial page update :

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

It was particularly useful for displaying a message to the user to indicate something was happening...

Good luck,

Bob


I ended up just using this in the codebehind of the ascx:

ScriptManager.RegisterStartupScript(Page,typeof(PageTemplate),"Focus","focus();",true);

And including this function in a .js file (one line for each section):

function focus() {
try { window.location.href='#IA'; } catch (err) {}
try { window.location.href='#IB'; } catch (err) {}
try { window.location.href='#IC'; } catch (err) {}
try { window.location.href='#ID'; } catch (err) {}
try { window.location.href='#IIA'; } catch (err) {}
try { window.location.href='#IIB'; } catch (err) {}
try { window.location.href='#IIC'; } catch (err) {}
}

Seems to work on all but the initial page change, which is 'good enough' for me at this stage.

No comments:

Post a Comment