C# 如何在服务器端关闭 radwindow 并刷新父页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15640301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to close the radwindow on serverside and refresh the parent page
提问by Anyname Donotcare
I want to close the RadWindowand refresh the parent : how to do this server side :
我想关闭RadWindow并刷新父级:如何执行此服务器端:
I have the following case:
我有以下情况:
Two pages say :
两页说:
parent.aspx :
父.aspx:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableViewState ="false">
</telerik:RadWindowManager>
and parent.cs
和 parent.cs
protected void OpenNewWindow(string url, int width, int height,int mode)
{
RadWindow newWindow = new RadWindow();
newWindow.NavigateUrl = url;
newWindow.VisibleOnPageLoad = true;
newWindow.KeepInScreenBounds = true;
if (width > 0)
{
newWindow.Width = width;
}
if (height > 0)
{
newWindow.Height = height;
}
newWindow.VisibleStatusbar = false;
if (mode == 0)
{
newWindow.DestroyOnClose = true;
newWindow.InitialBehaviors = WindowBehaviors.Maximize;
}
RadWindowManager1.Windows.Add(newWindow);
}
i call this method in the rowcommand of some gridview on my parentpage :
我在父页面上的某些 gridview 的 rowcommand 中调用此方法:
like this :
像这样 :
OpenNewWindow("child.aspx", 0, 0,0);
Now i want on the server side click event of some button on the child
page to close the rad window and refresh the parent one how to do this ??
现在我想在child
页面上的某个按钮的服务器端单击事件关闭 rad 窗口并刷新父窗口如何执行此操作?
采纳答案by Win
As you said, you want to close from code behind. So you can render Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "refreshParentPage()", true);
from code behind to refresh the parent.
正如你所说,你想从后面的代码中关闭。所以你可以Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "refreshParentPage()", true);
从后面的代码渲染来刷新父级。
Just add the following code and script in Child Page. No code is needed in parent page.
只需在子页面中添加以下代码和脚本。父页面不需要代码。
<script>
function getRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
// Reload parent page
function refreshParentPage() {
getRadWindow().BrowserWindow.location.reload();
}
</script>
<asp:Button runat="server" Text="Close" ID="CloseButton"
OnClick="CloseButton_Click"/>
protected void CloseButton_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CloseScript", "refreshParentPage()", true);
}
Update:
更新:
// Redirect page page to url
function redirectParentPage(url) {
getRadWindow().BrowserWindow.document.location.href = url;
}
// Code behind
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CloseScript", "redirectParentPage('Parent.aspx')", true);
回答by McCee
You should use the getRadWindow().close()
method and the OnClientClose
event.
您应该使用getRadWindow().close()
方法和OnClientClose
事件。
On Child.aspx:
在 Child.aspx 上:
<script type="text/javascript">
function getRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function clientClose(arg) {
getRadWindow().close(arg);
}
</script>
In Child.cs:
在 Child.cs 中:
protected void btn_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "closeScript", "clientClose('');", true);
}
When creating your RadWindow in Parent.cs, add the OnClientClose
event: newWindow.OnClientClose = "OnChildWindowClosed";
.
在 Parent.cs 中创建 RadWindow 时,添加OnClientClose
事件:newWindow.OnClientClose = "OnChildWindowClosed";
。
And on Parent.aspx:
在 Parent.aspx 上:
<script type="text/javascript">
function OnChildWindowClosed(sender, eventArgs) {
document.location.reload(); // there may be a cleaner way to do the refresh
}
</script>
回答by Ahmed Ibrahim
Simple way to force closing rad window, just put it inside update panel like that :
强制关闭 rad 窗口的简单方法,只需将其放入更新面板中即可:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Block">
<ContentTemplate>
<telerik:RadWindow ID="RadWindow1" runat="server">
<ContentTemplate>
</ContentTemplate>
</telerik:RadWindow>
</ContentTemplate>
</asp:UpdatePanel>
Important: you have to apply this properties to the update panel :
重要提示:您必须将此属性应用于更新面板:
UpdateMode="Conditional" RenderMode="Block"
更新模式=“条件”渲染模式=“块”
?
?
then inside the button you want to execute the close command perform :
然后在要执行关闭命令的按钮内执行:
UpdatePanel1.update()
this command will close radwindow and no refresh to your Webpage and no need to javascript, I tried it.
此命令将关闭 radwindow 并且不会刷新您的网页,也不需要 javascript,我试过了。