Solved

Closing Browser Window C#

Posted on 2007-11-22
8
8,959 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c#, datatable, aspx 4 47
C# LINQ query question 11 29
Error in Visual Project 10 46
Need Help With GDI+ in VB.Net 8 38
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

737 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