Solved

Closing Browser Window C#

Posted on 2007-11-22
8
8,951 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

706 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

18 Experts available now in Live!

Get 1:1 Help Now