473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Close a browser

How Can I Close the browser using asp.net button
Jun 28 '07 #1
6 1395
r035198x
13,262 8TB
How Can I Close the browser using asp.net button
Do not post questions in the articles section.
Moved to the forum.
Jun 28 '07 #2
nateraaaa
663 Expert 512MB
How Can I Close the browser using asp.net button
You would need to wire the click event to a javascript window.Close() call.

Expand|Select|Wrap|Line Numbers
  1. <asp:Button id="btnClose" runat="server"></asp:Button>
Page_Load event
Expand|Select|Wrap|Line Numbers
  1. btnClose.Attributes.Add("onclick", "window.close();")
Nathan
Jun 28 '07 #3
TRScheel
638 Expert 512MB
How Can I Close the browser using asp.net button

This is unexpected behavior on the part of the user. You have to ask yourself why do you want this to happen? Is it needed? Also, some browsers may even pop up an error to the user telling them something is trying to close the browser.

If you have though of all that, then I can tell you that the simplest way to do this is with javascript.

Expand|Select|Wrap|Line Numbers
  1. window.close()
  2.  
That code will close the window, and if you put it within a button, it will do the job. Its not C# or VB .Net though. I do not think it is even possible in an unscripted language.
Jun 28 '07 #4
Frinavale
9,735 Expert Mod 8TB
Hi sri9440071311,
Welcome to TSDN! I hope you like it here :)

You can't use asp to close a window but you can use JavaScript.
So what you need to do is add this little bit of JavaScript code to the page with your button on it.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.      function CloseWindow()
  4.      {
  5.           window.Close();
  6.      }
  7. -->
  8. </script>
  9.  
See this thread for instructions on how to add JavaScript code to your page.

Then in your server side code, in your Page_Load method you want to add:
(code in vb)
Expand|Select|Wrap|Line Numbers
  1.  BTN_Close.Attributes.Add("OnClick", "CloseWindow();")
  2.  
Cheers!
-Frinny
Jun 28 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
This thread is being moved to the Javascript forum.

ADMIN
Jun 28 '07 #6
Frinavale
9,735 Expert Mod 8TB
You would need to wire the click event to a javascript window.Close() call.

Expand|Select|Wrap|Line Numbers
  1. <asp:Button id="btnClose" runat="server"></asp:Button>
Page_Load event
Expand|Select|Wrap|Line Numbers
  1. btnClose.Attributes.Add("onclick", "window.close();")
Nathan
I like this solution best :)
I don't know why I always do things the hard way.

Nice answer Nathan!
:)

-Frinny
Jun 28 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk...
6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
3
by: Denon | last post by:
How to trap browser close event in SERVER side? I read a lot of forum message, it talk about onclose(), onunload() and even onbeforeunload() event. However, all of theses are based on javascript...
3
by: Gin Lye | last post by:
Does any one know to close the web browser automatically after logging off Your help will be appreciated gin lye
4
by: Ron Lautmann | last post by:
I want to close a browser window so I created a Close button that does this: private void Button1_Click(object sender, System.EventArgs e) {...
7
by: Paul | last post by:
Hi I have a web application that has a log off selection, just redirects the browser to a form with a label displaying you are loging off. In part of the application I open a new window and was...
5
by: Randy | last post by:
Hello, I'm trying to find a way to close the browser with out the IE security message "The Web page you are viewing is trying to close the window." message. I know how to close the browser using...
37
by: Jan Tovgaard | last post by:
Hey everyone:) We have a critical problem, which I can see that other people also has ran into. In Internet Explorer 7 it is no longer possible to do a window.close after opening a window,...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
5
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.