简体   繁体   English

从服务器显示Telerik RadWindow,同时保持滚动位置

[英]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. 在滚动到页面底部时显示RadWindow时,该窗口将呈现在页面顶部,并且我必须向上滚动才能看到该窗口。

I'm maintaining post back scroll position by setting 'MaintainScrollPositionOnPostback': 我通过设置'MaintainScrollPositionOnPostback'来保持后退滚动位置:

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

I have a RadListView where the ItemTemplate has a button in it. 我有一个RadListView,其中ItemTemplate中有一个按钮。 When that button is clicked, I display a RadWindow modal. 单击该按钮时,将显示RadWindow模态。

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). 问题是,如果我滚动到页面底部并单击按钮,页面将在页面顶部显示该窗口,然后向下滚动到用户滚动到的位置(由于MaintenanceScrollPositionOnPostback)。 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? 如何显示RadWindow在回发时用户在哪里滚动? (Not at top of page) (不在页面顶部)

I've tried displaying RadWindow 2 different ways but both have same result 我尝试过以不同的方式显示RadWindow 2,但两者的结果相同

Way 1: 方法1:

Window.VisibleOnPageLoad = true;

Way 2: 方式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. show()周围添加一个超时,以便在打开RadWindow之前进行滚动。 Otherwise, here is what happens: 否则,将发生以下情况:

  1. postback returns, page is not scrolled 回发返回,页面不滚动

  2. RadWindow shows up, centers in the current viewport RadWindow显示,位于当前视口的中心

  3. scrolling shifts so your RadWindow is not where you expect it 滚动移动,因此您的RadWindow不在您期望的位置

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. 您可以在此处调整我为说明目的添加的111ms超时。 Using 0 as an argument may also suffice. 使用0作为自变量也可以满足要求。 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 顺便说一句,我将在标记中创建一个JS函数,该函数将RadWIndow的ID作为参数并调用它,以使代码更具可读性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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