Connecting Tech Pros Worldwide Forums | Help | Site Map

Create an exit button in C#

Newbie
 
Join Date: Apr 2009
Posts: 17
#1: Jun 25 '09
Hi,

Can someone please help me with an exit button in C#. I have an exit button that does not work.

Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#2: Jun 25 '09

re: Create an exit button in C#


By exit button do you mean a button to close the application?
You need to be a bit more specific in order for us to understand the problem you are facing.

If you do want a button to close the form, you can simply call the Dispose() method of the form.
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#3: Jun 25 '09

re: Create an exit button in C#


You are going to have to be FAR more specific than that. First, post the section of your code that isn't working, explain exactly what it is supposed to do, explain what it actually is doing, and post the error text, if any. Also let us know if this is a Windows Forms app or an ASP.NET app.

Then we might be able to help you.
nbiswas's Avatar
Member
 
Join Date: May 2009
Location: India
Posts: 34
#4: Jun 26 '09

re: Create an exit button in C#


Assuming windows application

Expand|Select|Wrap|Line Numbers
  1.  this.Close();
OR
Expand|Select|Wrap|Line Numbers
  1. this.Dispose();
Assuming Web Application,

It is always recommended to handle using client side scripting(e.g. Javascript)

On the button's client side click event call a function say "CloseMe()"

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.     function CloseMe()
  3.     {
  4.         window.close();
  5.  
  6.     }
  7.     </script>
But as the others mentioned, you should be more specific while asking your question.
Newbie
 
Join Date: Apr 2009
Posts: 17
#5: Jun 26 '09

re: Create an exit button in C#


Thanks it worked !
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#6: Jun 26 '09

re: Create an exit button in C#


You're welcome, glad we could help, but you please need to understand that this is a place where people from all over the world communicate via a written medium.

I know that its not always easy to express oneself, but could you please tell us the following so that this thread may still be of future use:

1. Was this a web based or form application?
2. Did you simply want to hide a form or remove it from memory?
3. Which solution worked for you?

By doing this someone else who is facing a similar problem may find their solution in this thread.
Newbie
 
Join Date: Apr 2009
Posts: 17
#7: Jun 26 '09

re: Create an exit button in C#


Hi,

it was a a Web application that needed to be removed from memory and I used

<script language="javascript" type="text/javascript">
function CloseMe()
{
window.close();

}
</script>
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#8: Jun 26 '09

re: Create an exit button in C#


Hi,

I'm not really involved in web programming, so i might be totally wrong here, but using that code on the client side will close the client side application, the server side code will still be in memory.

If you have a dedicated application on a web server, then this is totally correct, but if you wish that the server side memory also be freed, you will have to write C# code dispose of the application. Just something to keep in mind.

P.S. thanks for the extra details regarding your problem.
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#9: Jun 26 '09

re: Create an exit button in C#


For the record, I've never written anything to unload the session from the server's memory. Sessions expire on their own. Also, the app is constantly running, otherwise it wouldn't be available from the web. So simply closing the page is a valid solution.

Make sure that you test that code in multiple browsers, not all of them implement JS in the same way.
Reply