ASP.NET ONPAGECLOSE事件
我试图找到一种从按钮打开页面的方法,如果它的 已经打开。
到目前为止,我拥有的是2页。 默认页面通过一个按钮打开选项页面,例如: -
protected void btnCreateNewWindow_Click(object sender, EventArgs e)
{
if (SharedMethods.Is_Page_Displayed == 0)
{
ClientScript.RegisterStartupScript(typeof(Page), "Order", "<script type='text/javascript'>window.open('Option1.aspx', '', 'fullscreen = yes')</script>");
SharedMethods.Is_Page_Displayed = 1;
}
}
共享会话代码: -
namespace ns_SharedMethods
{
public class SharedMethods
{
#region Session
public static String sIs_Page_Displayed = "Is_Page_Displayed";
#endregion Session
public static int Is_Page_Displayed
{
get
{
if (System.Web.HttpContext.Current.Session[sIs_Page_Displayed] != null)
{
return (Convert.ToInt32(System.Web.HttpContext.Current.Session[sIs_Page_Displayed]));
}
else
{
return (0);
}
}
set
{
System.Web.HttpContext.Current.Session[sIs_Page_Displayed] = value;
}
}
public static String Is_The_Page_Displayed()
{
if (Is_Page_Displayed == 1)
{
return ("YES");
}
else
{
return ("NO");
}
}
}
}
我尝试使用的是将会话变量用作标志来表示该页面已打开/关闭。
是否可以在第二页中触发OnClosePage事件来设置会话变量“ IS_PAGE_DISPLAYED = 0”?
任何例子都将不胜感激。
TIA
PS我试图发布所有页面.aspx源代码,但是格式正在扭曲:(
I'm trying to find a way of opening a page from a button if its NOT already open.
What I have so far is 2 pages.
Default page opens Option page via a button like:-
protected void btnCreateNewWindow_Click(object sender, EventArgs e)
{
if (SharedMethods.Is_Page_Displayed == 0)
{
ClientScript.RegisterStartupScript(typeof(Page), "Order", "<script type='text/javascript'>window.open('Option1.aspx', '', 'fullscreen = yes')</script>");
SharedMethods.Is_Page_Displayed = 1;
}
}
Shared Session code:-
namespace ns_SharedMethods
{
public class SharedMethods
{
#region Session
public static String sIs_Page_Displayed = "Is_Page_Displayed";
#endregion Session
public static int Is_Page_Displayed
{
get
{
if (System.Web.HttpContext.Current.Session[sIs_Page_Displayed] != null)
{
return (Convert.ToInt32(System.Web.HttpContext.Current.Session[sIs_Page_Displayed]));
}
else
{
return (0);
}
}
set
{
System.Web.HttpContext.Current.Session[sIs_Page_Displayed] = value;
}
}
public static String Is_The_Page_Displayed()
{
if (Is_Page_Displayed == 1)
{
return ("YES");
}
else
{
return ("NO");
}
}
}
}
I've tried is using a Session variable as a flag to denote the page is open/closed.
Is it possible to trigger an OnClosePage event in the second Page to set a Session variable "Is_Page_Displayed = 0"?
Any examples is appreciated.
tia
PS I've tried to publish all pages .aspx source code but the formatting was being distorted :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于使用的初始代码,添加: -
在“ option1.aspx”上
将其添加到源: -
在“&lt; body&gt;&lt; form id =“ form1” runat =“ server”&gt;“”下。
将其添加到Option1.aspx.cs: -
因此,我所做的就是使用window.onbeforeunload事件,在Option1.aspx中,调用C#方法来设置会话变量。 default.aspx页面在尝试打开option1.aspx之前检查
Base on the initial code used, add:-
On "Option1.aspx"
Add this to the source:-
And this under the "< body > < form id="form1" runat="server" >"
Add this to the Option1.aspx.cs:-
So what I've done is use the window.onbeforeunload event, in Option1.aspx, to call a C# method to set a Session variable. The Default.aspx page checks prior to trying to open Option1.aspx