我有一个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); }
解决方案你不能关闭用户服务器的窗口。 用java脚本关闭它。使用javascript返回(部分)视图。 只需在这里调用window.close()。 function openWin(){ myWindow = window.open(,myWindow,width = 200,height = 100); //打开一个新窗口} 函数closeWin(){ myWindow.close(); //关闭新窗口}
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); }
解决方案 You can't close the window of a user server sided. Close this with java-script. Return a (partial)view with a javascript. Just call window.close() here. function openWin() { myWindow = window.open("", "myWindow", "width=200, height=100"); // Opens a new window } function closeWin() { myWindow.close(); // Closes the new window }更多推荐
在javascript中的Window.close()
发布评论