I'm trying to close and application using C# and ASP.NET. I've tried system.windows.forms.application.exit() but it just refreshes the screen. I tried Environment.Exit(0) but that just ended the application and returned an error in the browser. Please help anyway you can!! Thanks!

Hi,

Try this code tha use JavaScript.

<html>
<head>
    <title>Test</title>
</head>
<body>
<form>
  <input type="button" onclick="self.close();" value="Close" />
</form>
</body>
</html>

Regards,
Camilo

Hi,

Try this code tha use JavaScript.

<html>
<head>
    <title>Test</title>
</head>
<body>
<form>
  <input type="button" onclick="self.close();" value="Close" />
</form>
</body>
</html>

Regards,
Camilo

This is not possible since the button that will close is the Submit button so the onclick function has other actions to it as well. Does c# not have a way to close the app?

What are you trying to do? It sounds like you want to clear the session variables? The application will reinitialize itself after you call close if the client requests any more data.

What do you need exactly?

What do you need exactly?

This thread is a year old, we've been had :(

I would like after the submit button is hit to close the window completely

This thread is a year old, we've been had :(

Project was put on hold and code lost. Now i am at the same point and figured to use the same thread to find an answer.

You need to press a button on web form to close a window in windows-based application?

Great! Help him/her. Poster trying to close an asp.net web application and web browser since Jul 16th, 2008.

After all post#2 is your solution.
Mark this thread as Solved and create a new Thread in HTML forum.

Great! Help him/her. Poster trying to close an asp.net web application and web browser since Jul 16th, 2008.

After all post#2 is your solution.
Mark this thread as Solved and create a new Thread in HTML forum.

Like i said before, my onclick() function calls Submit_Click. So i cannot use self.Close() in there.

Like i said before, my onclick() function calls Submit_Click. So i cannot use self.Close() in there.

No, really, post #2 is your solution. Obviously this won't work right but its what you're asking for:

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" OnClientClick="javascript:self.close(); " />

I dont think the postback will occur if they select "OK" to closing the browser window. It sounds more like you're trying to post back and in the response have the browser close, but not as a client side event to clicking the button.

This thread has NOT BEEN SOLVED!!!!
The question was how to do it in C# NOT java...

I've been looking for the same thing for hours... how do I close the WEB app from the C# code behind page?!?!?
It's crazy that it should take this long to find out something so seemingly simple...

Will someone PLEASE Help!?

>how do I close the WEB app from the C# code behind page?!?!?

Nope! You can't. Of course using JavaScript you may close the browser but not an application. ASP.NET Web application can shutdown for a variety of reasons - when web-server itself is shutdown or application re-start itself in response to error conditions or changes in application's configurations.

wow... I'm rather amazed that it can't be done but thanks for providing the answer!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.