15

我有以下情况:

我的页面上有一个gridview:

page1.aspx

我在rad 窗口page2.aspx中通过该 gridview打开另一个页面( ),然后通过某个按钮打开最后一页()。page2.aspxpage3.aspxrad window

所有这些步骤都是通过服务器端代码执行的:


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

我想做的是:

当单击 my ( page3.aspx) 上的特定按钮时,关闭它及其父级page2.aspx

如何做到这一点(服务器端)?

我试试这个:但它只是关闭了page3.aspx我想关闭父母的孩子page2.aspx?!


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

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

3 回答 3

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

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

如果CloseModal()事件正确触发,您应该能够在window.close()其中调用。RadWindows 仅存在于父窗口的上下文中,因此您仍然应该能够调用window.close()which 将关闭每个打开的窗口。

编辑:虽然有点离题,但 Telerik 的这个链接向您展示了如何从 RadWindow 获取父窗口的句柄。然后你可以调用客户端的close方法关闭浏览器窗口(page1.aspx),这将关闭所有后续的RadWindows。

这个链接

RadWindow 和浏览器的弹出窗口之间的主要区别在于,就像任何其他 DHTML 元素一样,RadWindow 仅存在于创建它的页面的上下文中。它不能离开浏览器窗口的边界。

于 2013-04-02T15:12:56.673 回答
7

您可以通过实现每个父级的接口来执行气泡事件。我试图说明我的想法。

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

这包括您必须将 RadWindow 声明为父级。因此,在似乎是这样的分层视图中:

PageA : IClosingParent
|
|-- PageB : IClosingParent
    |
    |-- 页面C
        |--关闭按钮

我认为您可以使用此解决方案来管理您想要的关闭过程,并随时或随心所欲地进行更改。

于 2013-04-05T14:45:55.390 回答
2

这可能听起来很土,但是为什么不简单地在关闭之前执行要运行的服务器代码,然后向客户端返回一个 bool 参数,该参数允许它运行关闭窗口(客户端)的 if 语句?

PS:我在考虑算法,我对服务器端 C# 没有太多经验。

于 2013-04-02T10:23:47.107 回答