[英]C# ASP Callback Adding Class Issue
I created an app stand alone and it works with my callback. 我创建了一个独立的应用程序,它可以与我的回调一起使用。 I am trying to integrate it into a larger app and am having some issues.
我正在尝试将其集成到更大的应用程序中,并且遇到了一些问题。
My stand-alone app callback code: 我的独立应用程序回调代码:
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
}
Why can I not just add the class to my larger app like this: 为什么我不能像这样将类添加到我的大型应用程序中:
public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
In visual studio, I get an error that says 'page' interface name expected. 在visual studio中,我收到一个错误,表示预期的“页面”接口名称。
In the callback code itself, I get an error where it references to ClientScript saying 'cannot access static property 'clientSript' in nonStatic context'. 在回调代码本身中,我得到一个错误,它引用ClientScript,说“无法在非静态上下文中访问静态属性'clientSript'。
I do not really understand these terms... I do not have a CS degree or anything, so if anyone could explain this, that would be great (perhaps even the greatest), thanks! 我真的不明白这些条款......我没有CS学位或任何东西,所以如果有人能解释这一点,那将是伟大的(甚至可能是最伟大的),谢谢!
C# does not support multiple inheritance, so you cannot do the following line: C#不支持多重继承,因此您无法执行以下操作:
public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
Just to clarify, the way you have written the above, the C# compiler thinks that abstractItemViewer is a class that you are trying to inherit from. 为了澄清一下,您编写上述内容的方式,C#编译器认为abstractItemViewer是您尝试继承的类。 The compiler then sees the "System.Web.UI.Page" part and is looking for an interface named that, it does not find it, because System.Web.UI.Page is a class and not an interface;
然后编译器看到“System.Web.UI.Page”部分,并且正在查找名为的接口,它找不到它,因为System.Web.UI.Page是一个类而不是接口; thus error.
因此错误。
You can, however, implement multiple interfaces, so you could do the following: 但是,您可以实现多个接口,因此您可以执行以下操作:
public class My_App_ItemViewer : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler, IAbstractItemViewer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.