0

我创建了一个独立的应用程序,它适用于我的回调。我正在尝试将其集成到更大的应用程序中,但遇到了一些问题。

我的独立应用回调代码:

public partial class Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //unimportant specific code

        //Get the Page's ClientScript and assign it to a ClientScriptManger
        ClientScriptManager cm = Page.ClientScript;

        //Generate the callback reference
        string cbReference = cm.GetCallbackEventReference(this, "arg", "HandleResult", "");

        //Build the callback script block
        string cbScript = "function CallServer(arg, context){" + cbReference + ";}";

        //Register the block
        cm.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true);

    }


    public void RaiseCallbackEvent(string eventArgument)
    {

        //unimportant specific code

        //This method will be called by the Client; Do your business logic here
        //The parameter "eventArgument" is actually the paramenter "arg" of CallServer(arg, context)

        GetCallbackResult(); //trigger callback
    }

    public string GetCallbackResult()
    {

        //unimportant specific code

        return callbackMessage;
    }

    //more specific unimportant stuff

}

为什么我不能像这样将类添加到我更大的应用程序中:

public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

在 Visual Studio 中,我收到一条错误消息,提示需要“页面”界面名称。

在回调代码本身中,我收到一个错误,它引用 ClientScript 说“无法在非静态上下文中访问静态属性 'clientSript'”。

我不太了解这些术语...我没有 CS 学位或任何东西,所以如果有人能解释这一点,那就太好了(甚至可能是最伟大的),谢谢!

4

1 回答 1

2

C# 不支持多重继承,因此不能执行以下行:

public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

只是为了澄清一下,按照您编写上述内容的方式,C# 编译器认为 abstractItemViewer 是您尝试继承的类。编译器然后看到“System.Web.UI.Page”部分并正在寻找一个名为 that 的接口,它没有找到它,因为 System.Web.UI.Page 是一个类而不是一个接口;因此错误。

但是,您可以实现多个接口,因此您可以执行以下操作:

public class My_App_ItemViewer : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler, IAbstractItemViewer
于 2013-06-21T14:28:15.093 回答