Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法访问Web控件中的公共方法';s页面加载事件_C#_Asp.net - Fatal编程技术网

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");