I have the following case:
我有以下情况:
I have a gridview on my page :
我的页面上有一个gridview:
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.
我通过rad窗口中的gridview打开另一个页面(page2.aspx),然后通过page2上的一些按钮。我也在rad窗口中打开最后一页(page3.aspx)。
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
.
当单击my (page3.aspx)上的特定按钮时,关闭它及其父页面2.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 ?!
我尝试了这个:但是它只是关闭子页面3。aspx我想关闭父页面2。aspx也? !
protected void Button1_Click(object sender, EventArgs e)
{
((RadAjaxManager)this.Parent.FindControl("RadAjaxManager1")).ResponseScripts.Add("CloseModal();");
RadAjaxManager1.ResponseScripts.Add("CloseModal();");
}
3 个解决方案
#1
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.
如果CloseModal()事件触发正确,则应该能够在其中调用windows .close()。RadWindows只存在于父窗口的上下文中,因此您仍然可以调用windows .close(),它将关闭打开的每个窗口。
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.
编辑:虽然有点偏离主题,但是来自Telerik的链接向您展示了如何从RadWindow获取父窗口的句柄。然后您可以调用close方法客户端来关闭浏览器窗口(page1.aspx),该窗口将关闭所有后续的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.
RadWindow和browser的弹出窗口之间的主要区别是,与任何其他DHTML元素一样,RadWindow只存在于创建它的页面的上下文中。它不能离开浏览器窗口的边界。
#2
7
You can do a bubble event by implement an interface a each parent. I try to illustrate my mind.
您可以通过实现每个父类的接口来实现一个bubble事件。我试图阐明我的思想。
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 :
这包括您必须将RadWindow声明为父窗口。所以在分层的观点中似乎是这样的:
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.
我认为你可以用这个解决方案来管理关闭过程就像你想要的那样,并随时改变。
#3
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) ?
这听起来可能有些老套,但为什么不简单地在关闭之前执行您想要运行的服务器代码,然后返回一个bool参数,允许它运行一个if语句来关闭窗口(客户端)呢?
PS : I'm thinking algorithmically, I don't have much experience with server-side C#.
我在用算法思考,我对服务器端c#没什么经验。
#1
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.
如果CloseModal()事件触发正确,则应该能够在其中调用windows .close()。RadWindows只存在于父窗口的上下文中,因此您仍然可以调用windows .close(),它将关闭打开的每个窗口。
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.
编辑:虽然有点偏离主题,但是来自Telerik的链接向您展示了如何从RadWindow获取父窗口的句柄。然后您可以调用close方法客户端来关闭浏览器窗口(page1.aspx),该窗口将关闭所有后续的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.
RadWindow和browser的弹出窗口之间的主要区别是,与任何其他DHTML元素一样,RadWindow只存在于创建它的页面的上下文中。它不能离开浏览器窗口的边界。
#2
7
You can do a bubble event by implement an interface a each parent. I try to illustrate my mind.
您可以通过实现每个父类的接口来实现一个bubble事件。我试图阐明我的思想。
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 :
这包括您必须将RadWindow声明为父窗口。所以在分层的观点中似乎是这样的:
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.
我认为你可以用这个解决方案来管理关闭过程就像你想要的那样,并随时改变。
#3
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) ?
这听起来可能有些老套,但为什么不简单地在关闭之前执行您想要运行的服务器代码,然后返回一个bool参数,允许它运行一个if语句来关闭窗口(客户端)呢?
PS : I'm thinking algorithmically, I don't have much experience with server-side C#.
我在用算法思考,我对服务器端c#没什么经验。