简体   繁体   English

如何在服务器端关闭radwindow并刷新父页面

[英]How to close the radwindow on serverside and refresh the parent page

I want to close the RadWindow and refresh the parent : how to do this server side : 我想关闭RadWindow并刷新父级:如何执行此服务器端:

I have the following case: 我有以下情况:

Two pages say : 两页说:

parent.aspx : parent.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窗口并刷新父窗口如何执行此操作?

As you said, you want to close from code behind. 正如你所说,你想要从背后的代码关闭。 So you can render Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "refreshParentPage()", true); 所以你可以渲染Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "refreshParentPage()", true); from code behind to refresh the parent. 从后面的代码刷新父。

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);

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>

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" UpdateMode =“条件”RenderMode =“Block”

then inside the button you want to execute the close command perform : 然后在你想要执行close命令的按钮内执行:

UpdatePanel1.update()

this command will close radwindow and no refresh to your Webpage and no need to javascript, I tried it. 这个命令将关闭radwindow而不刷新你的网页,不需要javascript,我试过了。

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

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