详细内容
.net利用ajax技术实现局部刷新
发布日期:2010-06-20     点击:3642     字体:[ ]

1.使用局部刷新,即不更新整个页面,利用ajax技术实现局部数据更新

2.首先页面需继承ICallbackEventHandler,并需实现该接口的两个方法

        public void RaiseCallbackEvent(string str)
        {
            //该方法获取要显示的数据       

        }

        public string GetCallbackResult()
        {

            //该方法返回值
            return _callBackResult;
        }

3.页面Page_Load事件注册脚本:

string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "getResultFromServer", "context");
string cbSrcipt = "function useCallBack(arg,context){" + cbReference + "}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "useCallBack", cbSrcipt, true);

4.html页面脚本定义

function getResultFromServer(arg,context)
{
//这里可以给页面上的控件赋值,即从后台获取的数据,例如;
   document.getElementById("txtPlanCost").value = arg;
}

 

5.调用,给页面上的某个控件设置调用,例如给也页面上一个下拉列表设置异步调用,当变更选项即局部刷新数据:

<asp:DropDownList ID="ddlStage" runat="server" Width="185px" onchange="useCallBack(this.options[this.selectedIndex].value);">
</asp:DropDownList>

用户评论
昵称:sd 来自:221.223.77.*  
2011/6/16 13:20:01
asdf
昵称 
内容  *
验证码   
   
相关文章 更多...  
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号 可人软件设计