我创建了一个独立的应用程序,它适用于我的回调。我正在尝试将其集成到更大的应用程序中,但遇到了一些问题。
我的独立应用回调代码:
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 学位或任何东西,所以如果有人能解释这一点,那就太好了(甚至可能是最伟大的),谢谢!