「クライアントコールバック」の編集履歴(バックアップ)一覧はこちら

クライアントコールバック - (2008/05/01 (木) 23:05:58) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

// 現在のページ名 *&this_page()  **概要 ASP.NETにおいて、クライアントサイドの処理から、サーバーサイドの変数等を扱う方法。 ***参照 -[[ICallbackEventHandler インターフェイス (System.Web.UI)>>http://msdn.microsoft.com/ja-jp/library/system.web.ui.icallbackeventhandler(VS.80).aspx]] ***元ネタ -[[「ASP.NET 2.0」クライアントコールバックのサンプル>>http://blogs.sqlpassj.org/mitsugi/archive/2006/01/17/15833.aspx]] **前提条件 -[[新しいwebサイトの作成]] **手順 default.aspx #highlight(csharp){{ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>クライアントコールバック - C#(ASP.NET V2.0)</title> <script type="text/javascript"> <!-- function LookUpStock() { var lb = document.forms[0].lbStock; var product = lb.options[lb.selectedIndex].text; CallServer(product, ""); } function ReceiveServerData(arg, context) { Results.innerText = arg; } --> </script> </head> <body onload="LookUpStock();"> <form id="frmMain" runat="server"> <div> <asp:ListBox ID="lbStock" runat="server"></asp:ListBox> <br /> <br /> <button onclick="LookUpStock();">Look Up Stock</button> <br /> <br /> Items in stock: <span id="Results"></span> <br /> </div> </form> </body> </html> }} default.aspx.cs #highlight(csharp){{ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Specialized; public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler { private string returnValue; private ListDictionary catalog; void Page_Load(object sender, EventArgs e) { // クライアント側コールバックスクリプト設定 ClientScriptManager clientScriptManager = (ClientScriptManager)Page.ClientScript; string cbReference = clientScriptManager.GetCallbackEventReference(this, "arg", "ReceiveServerData", ""); string callbackScript = "function CallServer(arg, context) {" + cbReference + "; }"; clientScriptManager.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true); // リストボックス this.catalog = new ListDictionary(); this.catalog.Add("monitor", 12); this.catalog.Add("laptop", 10); this.catalog.Add("keyboard", 23); this.catalog.Add("mouse", 17); this.lbStock.DataSource = this.catalog; this.lbStock.DataTextField = "key"; this.lbStock.DataBind(); lbStock.SelectedIndex = 0; } #region ICallbackEventHandler メンバ public string GetCallbackResult() { return this.returnValue; } public void RaiseCallbackEvent(string eventArgument) { if (this.catalog[eventArgument] == null) { this.returnValue = "-1"; } else { this.returnValue = this.catalog[eventArgument].ToString(); } } #endregion } }} &img(画像.jpg)
// 現在のページ名 *&this_page()  **概要 ASP.NETにおいて、クライアントサイドの処理から、サーバーサイドの変数等を扱う方法。 ***参照 -[[ICallbackEventHandler インターフェイス (System.Web.UI)>>http://msdn.microsoft.com/ja-jp/library/system.web.ui.icallbackeventhandler(VS.80).aspx]] ***元ネタ -[[「ASP.NET 2.0」クライアントコールバックのサンプル>>http://blogs.sqlpassj.org/mitsugi/archive/2006/01/17/15833.aspx]] **前提条件 -[[新しいwebサイトの作成]] **手順 default.aspx #highlight(html){{ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>クライアントコールバック - C#(ASP.NET V2.0)</title> <script type="text/javascript"> <!-- function LookUpStock() { var lb = document.forms[0].lbStock; var product = lb.options[lb.selectedIndex].text; CallServer(product, ""); } function ReceiveServerData(arg, context) { Results.innerText = arg; } --> </script> </head> <body onload="LookUpStock();"> <form id="frmMain" runat="server"> <div> <asp:ListBox ID="lbStock" runat="server"></asp:ListBox> <br /> <br /> <button onclick="LookUpStock();">Look Up Stock</button> <br /> <br /> Items in stock: <span id="Results"></span> <br /> </div> </form> </body> </html> }} default.aspx.cs #highlight(csharp){{ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Specialized; public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler { private string returnValue; private ListDictionary catalog; void Page_Load(object sender, EventArgs e) { // クライアント側コールバックスクリプト設定 ClientScriptManager clientScriptManager = (ClientScriptManager)Page.ClientScript; string cbReference = clientScriptManager.GetCallbackEventReference(this, "arg", "ReceiveServerData", ""); string callbackScript = "function CallServer(arg, context) {" + cbReference + "; }"; clientScriptManager.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true); // リストボックス this.catalog = new ListDictionary(); this.catalog.Add("monitor", 12); this.catalog.Add("laptop", 10); this.catalog.Add("keyboard", 23); this.catalog.Add("mouse", 17); this.lbStock.DataSource = this.catalog; this.lbStock.DataTextField = "key"; this.lbStock.DataBind(); lbStock.SelectedIndex = 0; } #region ICallbackEventHandler メンバ public string GetCallbackResult() { return this.returnValue; } public void RaiseCallbackEvent(string eventArgument) { if (this.catalog[eventArgument] == null) { this.returnValue = "-1"; } else { this.returnValue = this.catalog[eventArgument].ToString(); } } #endregion } }} &img(画像.jpg)

表示オプション

横に並べて表示:
変化行の前後のみ表示:
記事メニュー
目安箱バナー