在后台获取前台按钮里的值(如LinkButton)
前台ASPX:
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("id") %>' onclick="LinkButton1_Click" runat="server" CssClass="dayifen">打一分</asp:LinkButton>
后台CS:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
int newsId = int.Parse(btn.CommandArgument);
if (NewsManager.AddScore(newsId))
{
Response.Write("<script>alert(\"打分成功!\")</script>");
NewsListBind();
}
else
{
Response.Write("<script>alert(\"打分失败!\")</script>");
}
}
{
LinkButton btn = (LinkButton)sender;
int newsId = int.Parse(btn.CommandArgument);
if (NewsManager.AddScore(newsId))
{
Response.Write("<script>alert(\"打分成功!\")</script>");
NewsListBind();
}
else
{
Response.Write("<script>alert(\"打分失败!\")</script>");
}
}