在takako_mu 的基礎上補充我自己知道的另外兩種方法
http://topic.csdn.net/u/20090519/09/c14682c9-b3ec-45f7-a1bb-86872e28f942.html是第一種第二種:利用ICallbackEventHandler
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseICallbackEventHandler.aspx.cs" Inherits="UseICallbackEventHandler" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>未命名頁面</title>
     <%--
        該類繼承自 System.Web.UI.ICallbackEventHandler
        定義一個公用變量 rotected string returnValue;
        Server呼叫RaiseCallbackEvent方法進行事件處理
        GetCallbackResult方法將結果返回到Client
     --%>
    <script type="text/ecmascript">
        function PostValue()
        {
            CallServer(document.getElementById("TextBox1").value, "");
        }
        function ReceiveServerData(rValue)
        {
            document.getElementById("TextBox2").value = rValue;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
        <input type="button" onclick="PostValue();" value="......" />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class UseICallbackEventHandler : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
    protected string returnValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
        string callbackScript;
        callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        returnValue = "Hello: " + eventArgument;
    }
    public string GetCallbackResult()
    {
        return returnValue;
    }
}

解决方案 »

  1.   

    第三種:利用UpdatePanel
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseUpdatePanel.aspx.cs" Inherits="UseUpdatePanel" EnableEventValidation="false" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>未命名頁面</title>
        <%--
            在用Button2調用Button1的事件的時候在Page中加上 EnableEventValidation="false" 
            利用UpdatePanel實現頁面局部刷新
         --%>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button1" />
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
            <input type="button" id="Button2" name="Button2" onclick="Fun()" value="Do Button1" />
        </div>
        </form>
        <script language="javascript" type="text/javascript">
        function Fun()
        {
            __doPostBack(form1.Button1.id, form1.Button1.value);
        }
        </script>
    </body>
    </html>using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class UseUpdatePanel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.TextBox2.Text = this.TextBox1.Text;
        }
    }
      

  2.   

    呵呵,我想你借助了很多工具,然后按工具分类之
    其实.你应该更注意更多一层js ->post/get url request->server ->response  ->解析,显示而你上面的解决方法均封装了这些步骤
    每个封装你称之为一个方法.呵呵.
      

  3.   

    是啊
    用的是VS2008自帶的ajax
      

  4.   

    ajax 当你真正熟悉了这4个字母的含义时,会写出比现在更符合题意的解决方案的。