C# 无法访问Web控件中的公共方法';s页面加载事件
我想从我的C# 无法访问Web控件中的公共方法';s页面加载事件,c#,asp.net,C#,Asp.net,我想从我的.ascx的页面加载事件调用我的公共字符串函数(…)方法。函数和包含类与web控件位于同一代码中。但我无法访问该功能。我如何解决这个问题 例如: public class Controls_WebApp : System.Web.UI.UserControl, IAttributeAccessor, IUserControlDesignerAccessor { protected void Page_Load(object sender, EventArgs e) {
.ascx
的页面加载事件调用我的公共字符串函数(…)
方法。函数和包含类与web控件位于同一代码中。但我无法访问该功能。我如何解决这个问题
例如:
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)
{
}
}
目前,您需要一个A
的实例来调用该方法
using namespaceOfA;
...
string result = new A().Function("Hello world");
或者,如果函数不依赖于的状态,则可以将函数设置为静态(公共静态字符串函数
)
你的问题不清楚。解释实际问题。根据您所描述的,您应该能够创建一个实例“var myClass=newa();”,然后调用您的方法“var result=myClass.Function(“some arg”);”
string result = A.Function("Hello world");