I would like to call my Public String Function(...)
method from my .ascx
's Page_Load
event. The function and containing class are located in the same code behind as the web control. But I am unable to access the function. How can I resolve this problem?
Example:
public class Controls_WebApp : System.Web.UI.UserControl, IAttributeAccessor, IUserControlDesignerAccessor
{
protected void Page_Load(object sender, EventArgs e)
{
// Call Function
}
}
public class A
{
public string Function(string path)
{
}
}
As it stands you will need an instance of A
to invoke the method
using namespaceOfA;
...
string result = new A().Function("Hello world");
Alternatively if the function has no reliance on the state of A, you can make the function static ( public static string Function
)
string result = A.Function("Hello world");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.