AjaxPro组件实现前后台数据无刷新交互

1、添加引用:AjaxPro.dll、Microsoft.AjaxCommon.dll。

2、web.config中加入:

  <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/>
    </httpHandlers>

3、Page_Load中加入:

AjaxPro.Utility.RegisterTypeForAjax(this.GetType(), this);

4、前台JS:

  <script type="text/javascript">
        function sentMes()
        {
            var _objData  = new Object();
           
            var _arr = new Array();
               
            for(var i=1; i<6; i++ )
            {
                var _row = new Object();
                 
                _row.StudentName = i+"1";
                _row.BirthdayFrom = i+"2";
                _row.BirthdayTo = i+"3";
               
                _arr.push( _row );
            }
           
            _objData.StudentList = _arr;
          
          
            return _objData;
        }
        function Button1_onclick()
        {
            var _objParaList=new Array;
            _objParaList=sentMes()
         
            this.ASP.Defaultss.SelectPage(_objParaList,SelectCallback);
           
        }
        function SelectCallback( _asyncObject )
        {
            //get result object
            var _paginationData = _asyncObject.value;
           
            Label1.innerHTML=_paginationData;
        }
    </script>

5、后台代码:

 

  [AjaxPro.AjaxMethod]
    public string SelectPage(IJavaScriptObject _ajaxReceiveData)
    {

        DataTable al = new DataTable();
        try
        {
            //get converter
            ScriptData _scriptData = Microsoft.AjaxCommon.Converter.GetScriptData(_ajaxReceiveData);

            //get query parameters
            al = _scriptData.GetTable("StudentList", "table0");
        }
        catch (Exception _err)
        {
            _err.Message.ToString();
        }

        //return
        return "1";
    }

 

posted on 2010-06-28 17:45  heart-in-sky  阅读(416)  评论(0编辑  收藏  举报