テキストボックスとボタンを含む* .aspxページがあります。ユーザーがテキストボックスに情報を入力して投稿をクリックすると、SQLデータベースにデータが挿入されます。問題は、ユーザーがリフレッシュすると、同じデータをデータベースに挿入し続けるということです。私はかなりの "クリック"メソッドは、単に挿入呼び出しではなく、呼び出されていると確信しています。私はセッションを混乱させようとしましたが、それは不満です。私は本当に何をすべきかはわかりません。私は簡単な簡単な修正を探しています。Asp.Net SQL Refreshページの重複挿入?
protected void PostButton_Click(object sender, EventArgs e)
{
string wpost = (string)Session["WallPost"];
DateTime wtime = (DateTime)Session["WallDateTime"];
if (txtWallPost.Text.Length > 0 && !wpost.Equals(txtWallPost.Text))
{
string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SocialSiteConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strCon))
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "INSERT INTO [WallTable] ([UserId], [FriendId], [WallPost]) VALUES (@UserId, @FriendId, @WallPost)";
cmd.Parameters.AddWithValue("@UserId", User.Identity.Name);
cmd.Parameters.AddWithValue("@FriendId", User.Identity.Name);
cmd.Parameters.AddWithValue("@WallPost", txtWallPost.Text);
conn.Open();
cmd.ExecuteNonQuery();
Session.Add("WallPost", txtWallPost.Text);
Session.Add("WallDateTime", new DateTime());
conn.Close();
txtWallPost.Text = "";
LoadWallPosts();
}
}
}
return;
}
[繰り返されるポストバックが私のビジネスレイヤーを混乱させないようにする方法](http://stackoverflow.com/questions/481564/how-to-prevent-repeated-postbacks-from-confusing-my-business-layer ) –