最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to close the radwindow on serverside and refresh the parent page - Stack Overflow

programmeradmin1浏览0评论

I want to close the RadWindow and refresh the parent : how to do this server side :

I have the following case:

Two pages say :

parent.aspx :

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableViewState ="false">
</telerik:RadWindowManager>

and 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 :

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 ??

I want to close the RadWindow and refresh the parent : how to do this server side :

I have the following case:

Two pages say :

parent.aspx :

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableViewState ="false">
</telerik:RadWindowManager>

and 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 :

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 ??

Share Improve this question asked Mar 26, 2013 at 14:58 Anyname DonotcareAnyname Donotcare 11.4k72 gold badges228 silver badges408 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

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.

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.

On 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:

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";.

And on 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 :

<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.

发布评论

评论列表(0)

  1. 暂无评论