【发布时间】:2013-12-19 20:54:46
【问题描述】:
在我的 gridview 中,我包含了一个包含 LinkButton 的列,它允许您删除 LinkButton 所在的同一行上的记录:
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="lnkDeleteTxn" Text="Delete" runat="server" CommandArgument='<%# Eval("TxnID") %>' OnClick="deleteTxn"
OnClientClick="return confirm('!!--WARNING--!! You are about to delete the transaction. Performing this action will permanently remove the transaction and all its details from the database. Proceed?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
这个LinkButton 包括显示一个弹出窗口,询问用户是否真的要删除记录。现在,对于我的RowDataBound 事件,我将其设置为,只要记录的状态为“已批准”,删除链接按钮就会被禁用:
string recStatus = Convert.ToString(DataBinder.Eval(e.Row.DataItem,"StatusDesc"));
if (recStatus == "Approved")
{
hlTxnEdit.Enabled = false;
lnkTxnDelete.Enabled = false;
}
else
{
hlTxnEdit.Enabled = true;
lnkTxnDelete.Enabled = true;
//lnkTxnDelete.Attributes.Add("OnClientClick", "return confirm('!!--WARNING--!! You are about to delete the transaction. Performing this action will permanently remove the transaction and all its details from the database. Proceed?')");
}
问题是,当用户单击禁用的 LinkButton 时,仍会显示确认弹出窗口,但它不应该显示,因为 LinkButton 已禁用。有点道理,因为设置弹窗的Attribute在OnClientClick属性上。如何使弹出窗口不显示?我尝试在后面的代码中添加OnClientClick 属性,但它不起作用。 LinkButton 直接删除记录。
【问题讨论】: