Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
How can I call a public static method of a class from a click of a button?

For example I have a button call record. Instead of putting the whole code behind the button I want it to call the method of a class that will call recording

Thanks Guys!
Posted
Updated 28-Oct-10 5:55am
v2
Comments
Dalek Dave 28-Oct-10 11:55am    
Edited for Grammar and Readabiity.
Chirry 28-Oct-10 13:21pm    
yes that is what i wanted, thank you very much guys,
However; i am having a problem:
i got my class call record
This class have a method call rec
I reference the project GUI with the project where my class is
but When i try to write that piece of code when compile it says that the name record does not exist in the current context
where the error is?
thank you

Like this:

ClassName.MethodName(parameters...);
 
Share this answer
 
if it's a static method you call it by referencing to the class that contains the method, and not through an instance of that class.
so in the Click event of your button, you only need to write(supposing is C#):
protected void Button_Click(object sender, EventArgs e)
{
 Recording.Method();
}


is this what you are looking for?
 
Share this answer
 
Comments
Chirry 28-Oct-10 13:40pm    
tu hablas espanol?
You need to make sure that the namespace for the static class is included at the top of your file, or make the call like this
protected void Button_Click( object sender, EventArgs e )
{
    NameSpace.Recording.Method();
}
 
Share this answer
 

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