Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
This.Close();

This codes are not working in button.


The construct is as follows :

protected void btn_Close_Click(object sender, EventArgs e)
{
close();
}



Infact the Intellisense those not even pop-up when you start typing 'close'.

Pls assist
Posted
Updated 7-Jun-14 5:50am
v4
Comments
Emre Ataseven 7-Jun-14 11:19am    
change This to this then

Provided your code is inside a Form, rather than a UserControl, it will work:
C#
this.Close();
However, you don't need this in that context, the instance is implied:
C#
Close();
will have the same effect.

If you are in a UserControl, then you will have to create an event to ask the form to close: you shouldn't try to shut it yourself.
 
Share this answer
 
C#
protected void btn_Close_Click(object sender, EventArgs e)
{
this.close(); //this is the problem in your code.
}
 
Share this answer
 
Comments
Member 10744248 7-Jun-14 13:15pm    
how do you resolve this.
Dave Kreskowiak 7-Jun-14 14:34pm    
You don't. "this" refers to the current instance of the class in which it's used.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900