大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> Whidbey中客户端回调机制(二)

Whidbey中客户端回调机制(二)

时间: 2021-07-31 作者:daque

你将学会怎样抄写实行的代码,然而开始要处置还好吗处置存户端回叫效劳器而且处置效劳器回应的本领。 在功夫你也须要保护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 eventscboregion.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 第22中学的javascript因变量废除在country和city下拉框的数据( 即使有的话)。而后经过region和 the context参数挪用 callserver(在page_load中设置)本领。 region参数值是country + delimiter + region下拉框选中的

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.