有一个1.aspx1.aspx里有一个text,一个button,点击button会把text里的数据传到数据库,一般都会自动刷新,但要实现无刷新提交,怎么用AJAX实现呢??

解决方案 »

  1.   

    ScriptManager控件
    UpdatePanel控件
    在你的页面放上两个控件 <asp:ScriptManager ID="ScriptManager1" runat="server"><asp:UpdatePanel ID="UpdatePanel1" runat="server">    <ContentTemplate>        <!--你的表单-->    </ContentTemplate></asp:UpdatePanel>
      

  2.   

    可以实现吗?我弄了不来赛~
    我的代码是:
    Send.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Send.aspx.cs" Inherits="Send" %><!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>
        <script type="text/javascript">
            function SendData()
            {
                var seat="S006";    
                var xh = new ActiveXObject("MSXML2.XMLHTTP");   
                xh.open("POST","Do.aspx",false);
                xh.send(document.all.txtUser.value);  
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server" method="post">
            <div>
                <input id="txtUser" type="text" runat="server" />
                <input id="Button1" type="button" value="button" onclick="SendData()"/>
            </div>
        </form>
    </body>
    </html>Do.aspx.cs:public partial class Do : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {        SqlConnection con = new SqlConnection("Data Source=7E2DF151D5144A0\\SQLEXPRESS;Initial Catalog=TicketBook;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("update Seat set i_SeatState =@seatState where c_SeatCode=@seatCode", con);
            cmd.Parameters.AddWithValue("@seatState", "1");
            cmd.Parameters.AddWithValue("@seatCode", "S006");
            cmd.ExecuteNonQuery();
            con.Close();
        }但是do.aspx好像没有执行
    }
      

  3.   

            var xh = new ActiveXObject("MSXML2.XMLHTTP");  有问题??
      

  4.   

    楼主最好下载个VS2008的
    以前版本要求手动的手动修改web.config来激活asp.net应用程序的Ajax 
    但是 微软的2008 
    文件 |新建网站 创建新的web站点的时候 Ajax功能已经激活  哈哈 

    ScriptManager控件 
    UpdatePanel控件 封装下 就OK 挺傻瓜的吧 呵呵 百度 google 这方面的事例一片片 
    随便看看就行了哇。