AJax控件的应用

html代码:
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Style="height: 26px" />
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>


C#代码:
string s = this.TextBox1.Text;
        SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS;database=sale;User ID=sa;pwd=123");      
        con.Open();
        string sql="insert into test(v) values('"+s+"')";
        SqlCommand cmd = new SqlCommand(sql, con);
       int i= cmd.ExecuteNonQuery();
       if (i > 0)
       {
           
           ScriptManager.RegisterClientScriptBlock(UpdatePanel1,this.GetType(),"click","alert('插入成功')",true);
       
       }

你可能感兴趣的:(java,sql,c,Ajax,SQL Server)