Solved

Closing Browser Window C#

Posted on 2007-11-22
8
8,953 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now