How to close the parent window from its child?
Asked Answered
U

3

15

I have the following case:

I have a gridview on my page :

page1.aspx

I open another page(page2.aspx) through that gridview in a rad window then after that,through some button on page2.aspx i open the last page (page3.aspx) in a rad window also.

all these steps are performed through server side code :


 protected void OpenNewWindow(string url, int width, int height, int mode)
        {
            RadWindow newWindow = new RadWindow();
            newWindow.NavigateUrl = url;
            newWindow.VisibleOnPageLoad = true;
            newWindow.KeepInScreenBounds = true;
            newWindow.Skin = "Metro";
            if (width > 0)
            {
                newWindow.Width = width;


            }
            if (height > 0)
            {
                newWindow.Height = height;
            }
            newWindow.VisibleStatusbar = false;
            if (mode == 0)
            {
                {

                }
                //newWindow.OnClientClose = "OnChildWindowClosed";
                newWindow.DestroyOnClose = true;
                newWindow.InitialBehaviors = WindowBehaviors.Maximize;
            }
            RadWindowManager1.Windows.Add(newWindow);
        }

What i want to do is :

when clicking on a specific button on my (page3.aspx) close it and its parent page2.aspx.

How to do this (server side)?

I try this :but it just closes the child page3.aspx i want to close the parent page2.aspx also ?!


  protected void Button1_Click(object sender, EventArgs e)
        {
            ((RadAjaxManager)this.Parent.FindControl("RadAjaxManager1")).ResponseScripts.Add("CloseModal();");

            RadAjaxManager1.ResponseScripts.Add("CloseModal();");
        }
Ulu answered 28/3, 2013 at 14:30 Comment(5)
As soon as page2 and page3 are separate pages you can't easily close page 2 from page 3.Urbina
is page2.aspx the parent pf page3.aspx?Basically
yes page2.aspx has a button when i click on it opens page3.aspxUlu
Why you don't want to use client side?Heterogamy
because i do some server side code firstly before i close the childUlu
M
8
protected void Button1_Click(object sender, EventArgs e)
{
    ((RadAjaxManager)this.Parent.FindControl("RadAjaxManager1")).ResponseScripts.Add("CloseModal();");

    RadAjaxManager1.ResponseScripts.Add("CloseModal();");
}

If the CloseModal() event is firing correctly, you should be able to call window.close() within it. The RadWindows only exist in the context of the parent window so you should still be able to call window.close() which will close each window that's open.

Edit: although a bit off-topic, this link from Telerik shows you how to get a handle on the parent window from a RadWindow. Then you can call the close method client side to close the browser window (page1.aspx) which will close all subsequent RadWindows.

From this link:

The main difference between RadWindow and browser's popup is that just like any other DHTML element, RadWindow exists only in the context of the page in which it is created. It cannot leave the boundaries of the browser window.

Mcgill answered 2/4, 2013 at 15:12 Comment(0)
A
7

You can do a bubble event by implement an interface a each parent. I try to illustrate my mind.

public interface IClosingParent
{
    void Close();
}

public class PageA : System.Web.Page, IClosingParent
{
    public void IClosingParent.Close()
    {
        //Code to close it or hide it
    }
}

public class PageB : System.Web.Page, ClosingParent
{
    public void IClosingParent.Close()
    {
        ((IClosingParent)this.Parent).Close();

        //Code to close it or hide it
    }
}

public class PageC : System.Web.Page
{        
    protected void ButtonClose_Click(object sender, EventArgs e)
    {
        ((IClosingParent)this.Parent).Close();

        //Code to close it or hide it     
    }
}

That includes you must declare the RadWindow into the parent. So in a hierarchical view that seems to be like that :

PageA : IClosingParent
|
|-- PageB : IClosingParent
    |
    |-- PageC
        |-- ButtonClose

I think you can with this solution manage the closing process like you want and change whenever or whatever you want.

Alight answered 5/4, 2013 at 14:45 Comment(0)
H
2

This may sound rustic, but why don't you simply execute the server code you want to run before closing and then return to the client a bool parameter that allows it to run an if statement that closes the window (client-side) ?

PS : I'm thinking algorithmically, I don't have much experience with server-side C#.

Hanfurd answered 2/4, 2013 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.