当两个人同时点击LinkButton然后允许一个然后阻止另一个时,我怎么能这样做呢?我有这种形式,人们为自己声称记录,但问题是人们几乎同时点击LinkButton,然后它进入下一页,他们都认为记录是他们的。
ASP.NET
List
背后的代码
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="waitingRep" OnItemDataBound="waitingRep_ItemDataBound"
OnPreRender="waitingRep_PreRender" OnItemCommand="waitingRep_ItemCommand"
runat="server">
<ItemTemplate>
<asp:LinkButton ID="claimBtn" OnClick="claim" CommandArgument='<%# Eval("ID") %>' runat="server">
Claim
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
答案 0 :(得分:1)
删除选择并为更新添加额外条件,以避免更新(如果已经采用),如下所示:
bool isTaken = false;
using (SqlConnection conn = new SqlConnection(""))
{
SqlCommand cmd = new SqlCommand(@"UPDATE ClaimList set Status=@f1, ClaimedBy=@f2, ClaimedDate=@f3 where ID=@f4 AND Status <> 2", conn);
conn.Open();
cmd.Parameters.Add("@f1", SqlDbType.Int).Value = 2;
cmd.Parameters.Add("@f2", SqlDbType.Int).Value = logon_user;
cmd.Parameters.Add("@f3", SqlDbType.DateTime).Value = DateTime.Now.ToString();
cmd.Parameters.Add("@f4", SqlDbType.Int).Value = currentID;
if (cmd.ExecuteNonQuery() == 0)
isTaken = true;
}
if (!isTaken)
Response.Redirect("View.aspx?id=" + currentID);
else
Response.Redirect("Location.aspx?lid=" + location + "&action=taken");