如何在Asp.net中从.cs到.aspx.cs调用methode [英] How to call methode from .cs to .aspx.cs in Asp.net
本文介绍了如何在Asp.net中从.cs到.aspx.cs调用methode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有人都好,
请为我的问题提供一个答案..
Hai to all,
Please some one answer for my question..
推荐答案
您只需要创建该类的对象,如下所示:
在.cs中:
You just need to create the object of that class something like this:
in .cs:
class Alpha
{
public string mymethod(string name)
{
return name;
}
//if you have static method
public static int mysecondmethod(int age)
{
return age;
}
}
在.aspx.cs中:
in .aspx.cs:
Alpha obj=new Alpha();
obj.mymethod("ABC");
Alpha.mysecondmethod(20);
希望对您有所帮助:)
hope it helps :)
如果您的意思是从ASPX.CS文件中调用.CS文件中的方法,则只需将.CS文件放入您的App_Code文件夹中,然后
请通过类名引用静态方法:
If you mean call a method in a .CS file from a ASPX.CS file, then just put the .CS file in your App_Code folder, and
refer to the static methods by classname:
string s = MyClass.StaticMethod();
或创建该类的实例并在该实例上使用方法:
Or create an instance of the class and use the methods on the instance:
MyClass inst = new MyClass();
string s = inst.Method();
如果这不是您想要做的,请尝试更清楚地说明您要实现的目标.
If that isn''t what you want to do, then please try to explain more clearly what you are trying to achieve.
这篇关于如何在Asp.net中从.cs到.aspx.cs调用methode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文