Solved

Closing Browser Window C#

Posted on 2007-11-22
8
8,957 Views
Last Modified: 2013-12-16
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
Comment
Question by:stellyuk
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 7

Expert Comment

by:lucky_james
ID: 20333676
i think you need to handle using client side scripts.
check out:
http://forums.devx.com/archive/index.php/t-9129.html
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20333697
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
 
LVL 7

Expert Comment

by:bungHoc
ID: 20333719
This should work:
<input type="button" value="Close Window" onclick="window.close()">
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40

Expert Comment

by:evilrix
ID: 20333727
Yes, that might be what I meant -- like I said, I couldn't test it as I don't have .Net compiler handy :(
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 20333787
Response.Write("<script>window.close()</script>");
should also do.

Its was also there in the link i provided before.
0
 
LVL 2

Expert Comment

by:koolnurd
ID: 20334004
btnClosef.Attributes("onclick") = "javascript:return closeform()"

and in ur javascript

function closeform()
{
window.close();
return false;
}
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20334238
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
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20334246
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question