텍스트 상자와 단추가 포함 된 * .aspx 페이지가 있습니다. 사용자가 텍스트 상자에 정보를 입력하고 게시를 클릭하면 데이터가 SQL 데이터베이스에 삽입됩니다. 문제는 사용자가 새로 고침을 클릭하면 동일한 데이터를 데이터베이스에 계속 삽입한다는 것입니다. 나는 삽입 호출이 아니라 전체 "클릭"메소드가 호출된다고 확신한다. 세션을 망칠려고했지만 불평을합니다. 나는 무엇을해야할지 잘 모르겠다. 나는 쉬운 쉬운 문제를 찾고있다.Asp.Net SQL 새로 고침 페이지에 중복 삽입이 있습니까?
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) –