Default. aspx
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! 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> No title page </title>
<Script type = "text/javascript">
Function data_insert ()
{
Var xmlhttp;
If (window. ActiveXObject ){
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
Xmlhttp = new XMLHttpRequest ();
}
Else {
Alert ("your browser does not support ajax. Please use another one! ");
}
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
Alert ("yeah! ");
}
}
Var no, name;
No = document. getElementById ("TextBox1"). value;
Name = document. getElementById ("TextBox2"). value;
Var url = "Default2.aspx? No = "+ no +" & name = "+ name;
Xmlhttp. open ("get", url, true );
Xmlhttp. send (null );
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Number: <asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox> <br/>
Name:
<Asp: TextBox ID = "TextBox2" runat = "server"> </asp: TextBox> <br/>
<Input type = "button" value = "button" onclick = "data_insert ()"/>
</Div>
</Form>
</Body>
</Html>
Default. aspx. csCopy codeThe Code is as follows: using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
// Button1.Attributes. Add ("onclick", "date_insert ()");
}
}
Default2.aspx
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default2.aspx. cs" Inherits = "Default2" %>
<! 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> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: SqlDataSource ID = "SqlDataSource1" runat = "server"
ConnectionString = "<% $ ConnectionStrings: ConnectionString %>"
DeleteCommand = "delete from [tst] WHERE [no] = @ no"
InsertCommand = "insert into [tst] ([no], [name]) VALUES (@ no, @ name )"
SelectCommand = "SELECT * FROM [tst]"
UpdateCommand = "UPDATE [tst] SET [name] = @ name WHERE [no] = @ no">
<DeleteParameters>
<Asp: Parameter Name = "no" Type = "Int32"/>
</DeleteParameters>
<InsertParameters>
<Asp: Parameter Name = "no" Type = "Int32"/>
<Asp: Parameter Name = "name" Type = "String"/>
</InsertParameters>
<UpdateParameters>
<Asp: Parameter Name = "name" Type = "String"/>
<Asp: Parameter Name = "no" Type = "Int32"/>
</UpdateParameters>
</Asp: SqlDataSource>
<Br/>
</Div>
</Form>
</Body>
</Html>
Default2.aspx. cs
Copy codeThe Code is as follows: using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Public partial class Default2: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
SqlDataSource1.InsertParameters ["no"]. DefaultValue = http://www.jb51.net/wghost/archive/2011/12/01/Request.QueryString[ "no"]. ToString ();
SqlDataSource1.InsertParameters ["name"]. DefaultValue = http://www.jb51.net/wghost/archive/2011/12/01/Request.QueryString[ "name"]. ToString ();
SqlDataSource1.Insert ();
}
}