国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Whidbey中客戶端回調機制(二)

2024-07-21 02:16:26
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 你將學會如何書寫實施的代碼,但是首先要處理怎樣處理客戶端回叫服務器并且處理服務器回應的方法。 在期間你也需要保證callbackmanager 知道這種回叫客戶端方法。listing 1 顯示了page_load 事件。

    listing 1 :

    c#

    listing 1: registering client scripts:

    this code snippet from the default page's

    page_load event shows how you register client scripts.

    if (!page.ispostback)
    {
    // get the callbackevent reference.
    string bscript = page.getcallbackeventreference(this, "arg",
    "callbackhandler", "ctx", "errorcallback");
    stringbuilder sb = new stringbuilder();

    // create the javascript function that makes the
    // actual server call.
    sb.append("function callserver(arg,ctx)/n{/n");
    sb.append(bscript);
    sb.append("/n}");

    // register the clientscript.
    page.clientscript.registerclientscriptblock(this.gettype(),
    "callserver", sb.tostring(), true);
    // add attributes for onchange events
    cboregion.attributes.add("onchange", "selectregion();");
    cbocountry.attributes.add("onchange", "return selectcountry();");

    //fetch the regiondata and bind it to cboregion...



    getcallbackeventreference使得客戶端方法在客戶端請求結束時得到回收。 它也讓callbackmanager 確定產生哪種回叫方法。 在這個例子內使用的被重載的方法是:

    public string getcallbackeventreference(
    string target, string argument,
    string clientcallback, string context,
    string clienterrorcallback)
    table 1. getcallbackeventreference 方法的參數描述。
    parameters description target id of the page where the callback invocation is handled. for more see the other overloaded options available in the next immediate section.in our sample "this" is the argument value, since the callback is handled in the same page. argument this is the parameter defintion used to send value to the server. this value is received by parameter "eventargument" at the server end using the raisecallbackevent event."arg" becomes the first parameter name in our sample. the value is passed through this argument from the client. clientcallback method name of the callback that is invoked after successful server call."callbackhandler" is the method name that handles the callback. context a parameter that is associated with the "argument" from the client. it usually should be used to identify the context of the call. you will understand this better from the sample implementation.in the sample "ctx" is just another parameter definition used. the value for this is passed from the client. clienterrorcallback name of the method that is called from the callbackmanager in case of any errors.
    從這個方法返回的string是:


    __docallback('__page',arg,callbackhandler,ctx, errorcallback)

    另一個重載方法是:

    public string getcallbackeventreference(
    control control, string argument,
    string clientcallback, string context)

    public string getcallbackeventreference(
    control control, string argument,
    string clientcallback, string context,
    string clienterrorcallback)

    在上面listing 1顯示的兩種重載方法唯一不同是在使用control參數方面。當你在一個控件內處理icallbackeventhandler時,你便需要一個control參數。 下面,listing 1 顯示如下的代碼的部分:


    page.clientscript.registerclientscriptblock(
    this.gettype(), "callserver", sb.tostring(), true);
    the call to registerclientscript renders the client script block in the page output. if you "view source" in the resulting client page you'll see the code shown below.

    function callserver(arg,ctx)
    {
    __docallback('__page', arg, callbackhandler,
    ctx, errorcallback);
    }
    使客戶端發出回調你可以使用這個函數在客戶端請求結束時通過處理有關的 arg 和 ctx這兩個參數向服務器發出回叫請求。然而,你也應該考慮在asp.net第1 版本和2版本之間發生的registerclientscriptblock 定義方面的變化。在asp.net v2.0,你可以使用clientscriptmanager在目標頁面注冊腳本塊。 page.property clientscript 返回這個clientscriptmanager 方法。 可以在所注冊的腳本塊中選擇兩種重載的方法; 這是我為這個例子選擇的: public void registerclientscriptblock( type type, string key, string script, bool addscripttags) 表2顯示了回叫服務器的參數表2:arguments description type 這個參數使得registerstartupscript 和registerclientscriptblock 可以這冊相同名字的腳本塊而不會沖突。如:在例子中的this.gettype() key 腳本塊的標識.如:"callserver" . script 發出實際的腳本塊.在例子中stringbuilder提供了這個值. addscripttags 一個bool值true—在腳本結束時增加 "<script>" 標簽.
    你最后要做的事情就是在page load事件執行期間綁定region下拉框,以便使用戶選擇, 當page load事件執行時只有region下拉框被綁定。

    下一步是通過被選擇的地區。 從處理客戶端到服務器返回的值, 在page load事件執行時已經為下拉框增加 onchange屬性。如下:

    cboregion.attributes.add("onchange",
    "selectregion();");
    cbocountry.attributes.add("onchange",
    "selectcountry();");

    listing 2 顯示了selectregion 功能的實現。

    javascript listing 2: when regions change: the onchange event of the region dropdown listruns this javascript selectregion method. function selectregion(){//get the region dropdown(select) item.var region = document.all.item("cboregion") ;//if selected value is valid. if(region.options[region.selectedindex].value!=0) { //clear country box values var country = document.all.item("cbocountry") ; var countrylength = country.length; for(var countrycount=0;countrycount< } ,country.id); region.options[region.selectedindex].value + string.fromcharcode(20) callserver(?country? call. server the make city.remove(city.options[0]); { ++) citylength;citycount citycount="0;citycount" for(var citylength="city.length;" var ; city values. box select clear country.remove(countrycount);>
    在listing 2中的javascript函數清除在country和city下拉框的數據( 如果有的話)。然后通過region和 the context參數調用 callserver(在page_load中定義)方法。 region參數值是country + delimiter + region下拉框選中的值的組合。
    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 长宁县| 赣州市| 昌邑市| 富裕县| 安仁县| 察雅县| 三河市| 柏乡县| 务川| 鹤壁市| 连江县| 南溪县| 丰镇市| 琼海市| 珲春市| 屯留县| 苍溪县| 凤翔县| 慈溪市| 馆陶县| 邯郸市| 贺兰县| 花垣县| 淮滨县| 武夷山市| 乐业县| 日土县| 沁水县| 聂拉木县| 景德镇市| 呼图壁县| 探索| 婺源县| 新津县| 台中市| 友谊县| 富阳市| 泰兴市| 黑龙江省| 东辽县| 吉木乃县|