我建立了一个在某些帖子上需要点赞按钮的网站。
我制作了“喜欢”按钮,但是删除了“喜欢”按钮,一切都很好。
但是,当我创建具有“喜欢”数量的标签时,“喜欢”数量的更新面板在第一次单击时没有刷新,但是在第二次单击中,更新面板做出了我单击第一个按钮时应该做的事情时间。
请需要帮助。
<td align="left">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="Like" runat="server" class="ll glyphicon glyphicon-thumbs-up" OnClick="Like_Click"></asp:LinkButton>
<asp:LinkButton ID="dilike" runat="server" class="ll glyphicon glyphicon-thumbs-up" style="color:cornflowerblue" OnClick="dilike_Click"></asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Like" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="dilike" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
<td align="right">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dilike" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Like" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
protected void Like_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Session["login"]);
int postid = Convert.ToInt32(Request.QueryString["id"]);
string sql = "insert into likes([for],[by]) values(" + postid + "," + id + ")";
conDB.ExecuteNonQuery(sql);
dilike.Visible = true;
Like.Visible = false;
}
protected void dilike_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Session["login"]);
int postid = Convert.ToInt32(Request.QueryString["id"]);
string sql = "delete from likes where for=" + postid + " AND by=" + id + "";
conDB.ExecuteNonQuery(sql);
dilike.Visible = false;
Like.Visible = true;
}
PageLoad{
//check like
string sqll = "select by from likes where for="+postid+" AND by="+id+"";
if (conDB.ExecuteScalar(sqll) == null)
{
Like.Visible = true;
dilike.Visible = false;
}
else
{
dilike.Visible = true;
Like.Visible = false;
}
//count likes
string sqll2 = "select count(by) from likes where for=" + postid + "";
Label7.Text = conDB.ExecuteScalar(sqll2).ToString() + " Likes";
}