我现在正在学一本 书叫asp.net ajax程序设计  第II卷 microsoft ajax library 异步通信层 是陈黎夫写的 讲的都是客户端编程.

解决方案 »

  1.   

    微软教程(深入浅出AJAX)有讲这些的,很好很强大,讲得不错
      

  2.   

    是啊,用UpdatePanel太小题大作了,会的师傅指点一下.
      

  3.   

    JF,
    http://www.cnblogs.com/dflying/archive/2006/11/27/573860.html
      

  4.   

    首先页面上要有ScriptManager后台代码:using System.Web.Services;
    [WebMethod]
    public static DateTime GetCurrentTime()
    {
        return DateTime.UtcNow;
    }前台代码:<input type="button" value="Get Current Time" onclick="getCurrentTime()" />
        
    <script language="javascript" type="text/javascript">
    function getCurrentTime()
    {
    PageMethods.GetCurrentTime(getCurrentTimeSucceeded);
    }

    function getCurrentTimeSucceeded(result)
    {
    alert(result);
    }
    </script>
      

  5.   

     页面中 你是看不到 回调的。 封装好了,ASP.NET AJAX 第一卷 讲 UpdatePanel ,就是你把 以前 做的项目打开,把所有的控件放到 UpdatePanel 里面,执行的时候,无刷新,哈哈,完全不用改 任何代码,全部封装好了。ASP.NET AJAX 第二卷,讲 回调就非常详细了。 主要是 讲 客户端 调用 WebServices ,和 AjaxPro 原理 就有点像了。 
    建议你直接看第二卷 。
      

  6.   

    ASP.NET AJAX 是不需要用JS来调用客户端方法的.
    像服务器控件一样使用,只是他刷新的<UpdatePanel>内部内容.
    其实我也不怎么懂,用ASP.NET AJAX 可以给服务端方法传参数的吗?
      

  7.   

    把需要无刷新的控件放在UpdatePanel里就行了
    外面好象还要加个什么manage什么的
      

  8.   

        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (this.Page.IsPostBack)
                {
                    System.Threading.Thread.Sleep(3000);
                }
            }        protected void GvR_DataBound(object sender, GridViewRowEventArgs e)
            {
                GridView GV= (GridView)sender;            if (GV.SortExpression.Length > 0)
                {
                    int cellIndex = -1;
                    foreach (DataControlField field in GV.Columns)
                    {
                        if (field.SortExpression == GV.SortExpression)
                        {
                            cellIndex = GV.Columns.IndexOf(field);
                            break;
                        }
                    }                if (cellIndex > -1)
                    {
                        if (e.Row.RowType == DataControlRowType.Header)
                        {
                            e.Row.Cells[cellIndex].CssClass +=
                                (GV.SortDirection == SortDirection.Ascending? " sortascheader" : " sortdescheader");
                        }
                        else if (e.Row.RowType == DataControlRowType.DataRow)
                        {
                            e.Row.Cells[cellIndex].CssClass +=
                                (e.Row.RowIndex % 2 == 0? " sortaltrow" : "sortrow");
                        }
                    }
                }
            }        
            
        </script>
    <body>
        <form id="form" runat="server">
            <asp:ScriptManager runat="server" />
            <script type="text/javascript">
                function onUpdating(){
                    var pnlPopup = $get('<%= this.pnlPopup.ClientID %>');
                    var pnlPopupBounds = Sys.UI.DomElement.getBounds(pnlPopup);                var gridView = $get('<%= this.gvCustomers.ClientID %>');
                    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
                    
                    pnlPopup.style.display = '';     
     
                    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(pnlPopupBounds.width / 2);
                    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(pnlPopupBounds.height / 2);     
                    Sys.UI.DomElement.setLocation(pnlPopup, x, y);           
                }            function onUpdated() {
                    var pnlPopup = $get('<%= this.pnlPopup.ClientID %>'); 
                    pnlPopup.style.display = 'none';
                }                       
            </script>
            <div>
                <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:GridView 
                            ID="GridView1" runat="server" AllowSorting="true" 
                            OnRowDataBound="GvR_DataBound" AutoGenerateColumns="false">
                            <Columns>
                              ...
                            </Columns>
                        </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <ajaxToolkit:UpdatePanelAnimationExtender runat="server" TargetControlID="updatePanel">
                    <Animations>
                        <OnUpdating>
                            <Parallel duration="0">
                                <ScriptAction Script="onUpdating();" />  
                            </Parallel>
                        </OnUpdating>
                        <OnUpdated>
                            <Parallel duration="0">
                                <ScriptAction Script="onUpdated();" /> 
                            </Parallel> 
                        </OnUpdated>
                    </Animations>
                </ajaxToolkit:UpdatePanelAnimationExtender>            
            </div>
        </form>
    </body>
      

  9.   

    这个问题困扰我好久了,没用ajax时可以用_doPostBack实现,用了ajax后,好像button生成的html不一样了,现在用ajaxToolkit后,连onclick的代码都不生成了,真郁闷.
    9楼10楼的方法用的是静态方法,不实用,其实我自己都发现用gridview控件的oncommand事件可以期骗服务端,但太麻烦,
    有没有更好的方法,直接js 调用服务端代码,继续顶.谁有解块方案的加到200分都行.
    来抢分啊.
      

  10.   

    直接使用ajax来执行服务器代码就可以,什么dll都不需要给个简单的例子给你,获取服务器时间的test.aspx,注意名字不要改,要不需要修改对应的js
    <%@ Page Language="C#" debug="true"%>
    <script runat="server">
        void Page_Load(Object sender, EventArgs e)
        {
            if (Request.QueryString["readtime"] == "1")
            {
                Response.Write(ServerMethodGetTime());
                Response.End();//停止输出
            }
        }
        protected string ServerMethodGetTime()
        {
            return "服务器时间:" + DateTime.Now.ToString(); 
        }
    </script>
    <html>
      <head></head>
      <body>
      <input type="button" onclick="ExecServerMethod()" value="点我执行获取服务器时间的方法"/>
      <script type="text/javascript">
     function createObj()
    {
      var o=null;
      if(typeof(XMLHttpRequest)!="undefined") return new XMLHttpRequest();//ie7和w3c
      if(window.ActiveXObject)//ie6-
      {
        var MSXML=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHTTP"];
        for(var i=0;i<MSXML.length;i++)
        {
           try
           {
             o= new ActiveXObject(MSXML[i]);
             return o;
           }
           catch(e)
           {}
        }
      }
    }
    function ExecServerMethod()
    {
      var o=createObj();
      if(o)
      {
        o.onreadystatechange=function()
        {
          if(o.readyState==4)//已经返回
          {
             if(o.status==200)//成功返回
               alert(o.responseText);
             else
               alert("发生错误!");
          }
        }
        //如果你改了aspx的名称,注意这里要改成一样的名称,要不出现404错误
        o.open("get","test.aspx?readtime=1&rnd="+Math.random(),true);
        o.send(null);//发送请求
      }
      else
        alert("创建对象失败!");
    }
      </script>
      </body>
    </html>
      

  11.   

    回25楼:
    关键是,我如何通过JS调用后台代码刷新UpdatePanel呢?
      

  12.   

    不喜欢asp.net ajax.要是我我就手写..同意23楼的做法.
      

  13.   

    回25楼: 
    关键是,我如何通过JS调用后台代码刷新UpdatePanel呢?
    ==============================================
    不用寫JS代碼,都封裝好了,直接拿來用就OK了。
    配置好UpdatePanel就行了。
    這是asp.net ajax開發的初衷,傻瓜似的。
    如果要手寫代碼像ajax.net pro那樣,直接用ajax.net pro就OK了。不是沒人知道,是你的理解力有問題。