C#ASP回调添加类问题
本文关键字:问题 添加 回调 C#ASP | 更新日期: 2023-09-27 18:19:28
我单独创建了一个应用程序,它可以与我的回调一起工作。我正试图将它集成到一个更大的应用程序中,但遇到了一些问题。
我的独立应用程序回调代码:
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
在visualstudio中,我收到一个错误,上面写着"页面"接口名称。
在回调代码本身中,我收到一个错误,它引用了ClientScript,说"无法访问nonStatic上下文中的静态属性"clientSript"。"。
我真的不理解这些术语。。。我没有CS学位,所以如果有人能解释这一点,那就太好了(也许是最棒的),谢谢!
C#不支持多重继承,因此不能执行以下操作:
public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
为了澄清,正如您编写上述内容的方式一样,C#编译器认为abstractItemViewer是您试图从中继承的类。然后,编译器看到"System.Web.UI.Page"部分,并正在寻找一个名为"的接口,但没有找到,因为System.Web.UI_Page是一个类,而不是接口;从而产生误差。
但是,您可以实现多个接口,因此可以执行以下操作:
public class My_App_ItemViewer : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler, IAbstractItemViewer