谁能帮我看一下。。点击button1向数据库中插入一条数据,并绑定到gridview1,更新updatepanel1,在更新时我点击“取消”来取消异步回送。结果数据照样插入到表中,页面不更新了。我想要的效果是当点击“取消”的时候就不像数据库中增加数据。。怎么实现?
protected void Button1_Click1(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
string connstr=WebConfigurationManager.ConnectionStrings["mingcai_user_conn"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("o_income", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Tname", 0);
cmd.Parameters.AddWithValue("@userId", "9a23d3d4-c541-4d5b-9faa-f9a8cb10d505");
cmd.Parameters.AddWithValue("@inname", "哈哈");
cmd.Parameters.AddWithValue("@tmoney", "1234567");
cmd.Parameters.AddWithValue("@inwhere", "小金库");
cmd.Parameters.AddWithValue("@tdate", "2012-7-8");
cmd.Parameters.AddWithValue("@mood", "shuang");
cmd.Parameters.AddWithValue("@remark", "ceshi");
cmd.ExecuteNonQuery();
GridView1.DataBind();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
DataKeyNames="id" DataSourceID="SqlDataSource2">
ReadOnly="True" SortExpression="id" />
SortExpression="userid" />
SortExpression="in_name" />
SortExpression="tmoney" />
SortExpression="inwhere" />
SortExpression="remark" />
SortExpression="insert_time" />
ConnectionString="Data Source=DEVELOP-SERVER\OCHENGSHI;Initial Catalog=mingcai_database1;User ID=mc_admin"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [income]">
οnclick="Button1_Click1" />
runat="server" Text="取消" OnClientClick="abortTask()" />
function abortTask() {
var obj = Sys.WebForms.PageRequestManager.getInstance();
if (obj.get_isInAsyncPostBack())
obj.abortPostBack();
alert("终止!");
}