Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}
Posted
Updated 5-Apr-17 3:23am
v2

1 solution

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
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900