How can I close my web page application in asp C# when a button is clicked?

Posted on 2009-04-17
Last Modified: 2012-05-06
Hi, I want to close and exit my web page when a button is close.  How can I do this?  Thanks.
        protected void btnExit_Click(object sender, EventArgs e)
Question by:lapucca
    LVL 39

    Expert Comment

    What do you mean by "exit"? Do you mean to close the window? Or the browser completely? Or do you want to restart the web site on IIS? Or just show the entry page of your web site?
    LVL 39

    Accepted Solution

    Suppose you want to exit the whole browser: in most cases, cannot be done due to modern protection of the browser due to the tab pages etc.

    Suppose you want to exit only the current page, but leave the browser, by means of closing the window of the page: this can only be done when your application has opened the window. In that case, you can call:

    <input type="button" onclick="window.close();" value="close window" />

    which is client-side javascript, you cannot do this from the server.

    Suppose you want to exit the whole application on the server... well,... if you really want to do that I wouldn't mind diving into that, but your primary concern will be leveraging security.

    -- Abel --

    Author Comment

    Right, what you say makes a lot of sense.  I have been a windows developer and new to web development.  Of course, users would close the browser themself or change url to anther web page or we site.  I guess there is never any need for me to worry about closing anying page like I would in windows application.  Thank you.
    LVL 39

    Expert Comment

    you're welcome. And indeed, a web application always continues to run. Though matters of "starting" and "stopping" are done by means of logging in and out of the web application.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    745 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