问题描述
我有一个usercontrol,我想打开一个错误窗口来显示错误消息。我在ascx.cs中使用了window.open,窗口打开正确。
现在我想通过调用另一个方法来关闭打开的窗口,我在使用window.close()。
这对我不起作用。请帮帮我。
注意:当我使用IE调试器进行调试时,显示'ErrorWindow'未定义
我尝试过:
公共覆盖无效ErrorMessage()
{
string url = string.Empty;
ClientScriptManager cs = Page.ClientScript;
url =ErrorEnhanced.aspx;
输入cstype = this.GetType();
string script = string.Empty;
script =var ErrorWindow = window.open('+ url +', 'ErrorWindow','width = 400,height = 200,left = 550,top = 180,resizable = no,location = no,toolbars = 0,scrollbars = 0,statusbars = 0,menubar = 0')。focus() ;;
cs.RegisterStartupScript(cstype,Error_Script,脚本,true);
}
public override void CloseErrorWindow()
{
ClientScriptManager cs = Page.ClientScr ipt;
类型cstype = this.GetType();
string script = string.Empty;
script =var ErrorWindow; if(ErrorWindow!= null){;
script + =ErrorWindow.close();};
cs.RegisterStartupScript(cstype,Error_Script,script ,true);
}
I have a usercontrol where i want to open a error window to display error messages. I have used the window.open in ascx.cs, the window opened correctly.
Now i want to close the opened window by calling another method where i am using window.close().
It is not working for me. Please help me on this.
Note: when i debugged using IE debugger, It shows 'ErrorWindow' undefined
What I have tried:
public override void ErrorMessage()
{
string url = string.Empty;
ClientScriptManager cs = Page.ClientScript;
url = "ErrorEnhanced.aspx";
Type cstype = this.GetType();
string script = string.Empty;
script = "var ErrorWindow = window.open('" + url + "', 'ErrorWindow', 'width=400,height=200,left=550,top=180,resizable=no, location=no,toolbars=0,scrollbars=0,statusbars=0,menubar=0').focus();";
cs.RegisterStartupScript(cstype, "Error_Script", script, true);
}
public override void CloseErrorWindow()
{
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
string script = string.Empty;
script = "var ErrorWindow; if(ErrorWindow != null){";
script += "ErrorWindow.close();}";
cs.RegisterStartupScript(cstype, "Error_Script", script, true);
}
这篇关于在javascript中的Window.close()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!