[英]Cannot access Public method in Web Control's Page_Load event
I would like to call my Public String Function(...)
method from my .ascx
's Page_Load
event. 我想从我的
.ascx
的Page_Load
事件中调用我的Public String Function(...)
方法。 The function and containing class are located in the same code behind as the web control. 函数和包含类位于与Web控件相同的代码中。 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 就目前而言,您将需要一个
A
实例来调用该方法
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
) 或者,如果该函数不依赖于A的状态,则可以使该函数静态(
public static string Function
)
string result = A.Function("Hello world");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.