页面的布局是由一个textbox控件和一个dropdownlist控件,让用户查询按钮时,实现调用查询事件的功能。
<script type="text/javascript"> //客户端调用回调事件的代码 function FillData(){ var city=document.getElementById("TextBox1").value; <%=ClientScript.GetCallbackEventReference(this,"city","FillDll",null) %> } //填充下拉列表框的方法 function FillDll(strcity) { document.getElementById("DropDownList1").options.length=0; var indexofcity; var city; //切割传递来的字符串 while(strcity.length>0) { //判断是否是最后一个字符串 indexofcity=strcity.indexOf(","); if(indexofcity>0) { city=strcity.substring(0,indexofcity); strcity=strcity.substring(indexofcity+1); //填充下拉列表 document.getElementById("DropDownList1").add(new Option(city,city)); }else { //如果是最后一个字符串 document.getElementById("DropDownList1").add(new Option(strcity,strcity)); break; } } } </script>
在服务器端继承ICallbackEventHander类,生成回调的方法 public partial class CallBack :System.Web.UI.Page,ICallbackEventHandler { private string _data; protected void Page_Load(object sender, EventArgs e) { } //默认生成的回调方法 //#region ICallbackEventHandler 成员 //public string GetCallbackResult() //{ // throw new Exception("The method or operation is not implemented."); //} //public void RaiseCallbackEvent(string eventArgument) //{ // throw new Exception("The method or operation is not implemented."); //} //#endregion //回调事件的服务器方法 public string GetCallbackResult() { //返回处理后的数据; return _data; } public void RaiseCallbackEvent(string eventArgument) { //判断传递来的参数 switch (eventArgument) { case "北京": _data = "朝阳,海定,东城,西城"; break; case "上海": _data = "浦东,静安,虹口,徐汇"; break; case "济南": _data = "历下,历城,市中,天桥"; break; } } }
使用CallBack实现页面无刷新技术
最新推荐文章于 2021-12-11 22:36:30 发布