スタンドアロンのアプリを作成しましたが、コールバックで動作します。それをより大きなアプリに統合しようとしていますが、いくつかの問題があります。
私のスタンドアロン アプリのコールバック コード:
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 で、「ページ」インターフェイス名が必要であるというエラーが表示されます。
コールバック コード自体で、「非静的コンテキストで静的プロパティ 'clientSript' にアクセスできません」という ClientScript を参照するエラーが発生します。
私はこれらの用語をよく理解していません...私はCSの学位などを持っていないので、誰かがこれを説明できれば、それは素晴らしいことです(おそらく最高です)、ありがとう!