473,569 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close a browser

1 New Member
How Can I Close the browser using asp.net button
Jun 28 '07 #1
6 1407
r035198x
13,262 MVP
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Moderator Expert
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 Recognized Expert Moderator MVP
This thread is being moved to the Javascript forum.

ADMIN
Jun 28 '07 #6
Frinavale
9,735 Recognized Expert Moderator Expert
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
3630
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 for my session variable based security scheme. Basically, the risk is that a user will login to my site, close the window when done and allow...
6
8511
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 all works fine. If the user selects "Open" or "Cancel", the window closes, which is the desired behavior. If they select "Save", the location dialog...
3
11209
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 written on the client browser , like IE. To send a POST to web server to acknowledge its close event. However, I just think, web server and client...
3
1813
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
6317
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) { RegisterClientScriptBlock("GetData","<Script>close()</Script>"); } But when this runs the browser puts up a dialog box saying: "The web page you are viewing is trying to close the window, od you...
7
3041
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 wondering if there is a way to close all windows associated with the web application when the user selects the log off selection? Thanks. -- Paul G...
5
3156
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 Javascript (window.close()) but I would not like to get this message. Is there a way to close it in C#? Thanks
37
6285
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, without getting a alert message that ask if u want to close the window. This did NOT happen in Internet Explorer 6, Mozilla firefox or other browsers.
7
5803
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 to be two techniques for earlier versions. But the window.opener='' ;window.close(); and the window.open('','_parent','') ;window.close(); ...
5
34355
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 helps to recognise whether the close button is clicked( also differentiates whethet refresh was clicked). The problem arises whenever i try to close...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.