Link to home
Start Free TrialLog in
Avatar of stellyuk
stellyuk

asked on

Closing Browser Window C#

Hey there,

I was wondering if I could get a browser window to close using a button (using onclick event) in C#, if not how would I do this??

Stelly
Avatar of lucky_james
lucky_james
Flag of India image

i think you need to handle using client side scripts.
check out:
http://forums.devx.com/archive/index.php/t-9129.html
Avatar of evilrix
In the onclick event of your button in the .aspx code I think you just need to add window.close()

Something like this...

<asp:button onclick="window.close();" />

I don't have the ability to test this but I'm pretty sure it should work.
This should work:
<input type="button" value="Close Window" onclick="window.close()">
Yes, that might be what I meant -- like I said, I couldn't test it as I don't have .Net compiler handy :(
Response.Write("<script>window.close()</script>");
should also do.

Its was also there in the link i provided before.
btnClosef.Attributes("onclick") = "javascript:return closeform()"

and in ur javascript

function closeform()
{
window.close();
return false;
}
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note:

If you add the attribute in the code behind, this should be done in the Page_Load event so that it's there the first time you click the button, not in the Click event of the button.