[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8965
  • Last Modified:

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
0
stellyuk
Asked:
stellyuk
  • 2
  • 2
  • 2
  • +2
1 Solution
 
lucky_jamesCommented:
i think you need to handle using client side scripts.
check out:
http://forums.devx.com/archive/index.php/t-9129.html
0
 
evilrixSenior Software Engineer (Avast)Commented:
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.
0
 
bungHocCommented:
This should work:
<input type="button" value="Close Window" onclick="window.close()">
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
evilrixSenior Software Engineer (Avast)Commented:
Yes, that might be what I meant -- like I said, I couldn't test it as I don't have .Net compiler handy :(
0
 
lucky_jamesCommented:
Response.Write("<script>window.close()</script>");
should also do.

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

and in ur javascript

function closeform()
{
window.close();
return false;
}
0
 
Göran AnderssonCommented:
That should be:

btnClosef.Attributes("onclick") = "return closeform()"

The javascript: protocol is only used when you put Javascript in an URL. If you use it anywhere else, it becomes a label instead.
0
 
Göran AnderssonCommented:
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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now