简体   繁体   中英

Show Telerik RadWindow from Server while maintaining scroll position

When displaying a RadWindow while scrolled to the bottom of the page, the window is rendered at the top the of the page and I have to scroll back up to see the window.

I'm maintaining post back scroll position by setting 'MaintainScrollPositionOnPostback':

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="Default.aspx.cs"

I have a RadListView where the ItemTemplate has a button in it. When that button is clicked, I display a RadWindow modal.

The problem is if I scroll to the bottom of the page and click the button, the page displays the window at the top of the page, but then scrolls back down to where user was scrolled at (due to MaintainScrollPositionOnPostback). So the window is displayed off screen until user scrolls back up

How can I show the RadWindow where the user is scrolled at on postback? (Not at top of page)

I've tried displaying RadWindow 2 different ways but both have same result

Way 1:

Window.VisibleOnPageLoad = true;

Way 2:

string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);

Add a timeout around show() to let the scrolling take place before you open the RadWindow. Otherwise, here is what happens:

  1. postback returns, page is not scrolled

  2. RadWindow shows up, centers in the current viewport

  3. scrolling shifts so your RadWindow is not where you expect it

Here is an example:

string script = "function f(){setTimeout(function(){$find(\"" + RadWindow1.ClientID + "\").show(); },111);Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

where you can tweak the 111ms timeout I added for illustrative purposes. Using 0 as an argument may also suffice. To be honest, I don't know how long it takes for the scroll to shift.

By the way, I would create a JS function in the markup that would take the ID of the RadWIndow as an argument and call that instead, just to make the code more readable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM