在我下面粘贴的代码中,网格上有一个选项,可以在点击删除按钮时删除该行。在点击服务器端代码之前,我想要用户确认删除记录。
但是服务器端代码总是被命中,而不是首先显示的确认弹出窗口。
<asp:GridView ID="grdDelegateList" runat="server" CssClass="gridviewBorder" AutoGenerateColumns="False"
CellPadding="1" Style="margin-left: 0px" BackColor="White" Font-Names="Calibri"
BorderWidth="1px" Width="100%" AllowPaging="True" GridLines="Horizontal" RowHoverBackColor="#666666"
RowHoverForeColor="White" SelectedRowStyle-BackColor="#333333" SelectedRowStyle-ForeColor="White"
PageSize="10" OnPageIndexChanging="grdDelegateList_PageIndexChanging" OnRowCommand="grdDelegateList_RowCommand"
OnRowDataBound="grdDelegateList_RowDataBound" OnRowDeleting="grdDelegateList_RowDeleting">
<Columns>
<asp:BoundField HeaderText="Employee ID" DataField="DelegateID" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Full Name" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<p>
<%#DataBinder.Eval(Container.DataItem, "Owner.FirstName")%>
<%#DataBinder.Eval(Container.DataItem, "Owner.LastName")%>
</p>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remove" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<span style="cursor: pointer">
<asp:LinkButton ID="ImgRemove" runat="server" CommandName="Delete" CommandArgument='<%# Eval("ID") %>'
Text="Remove" OnClientClick="return confirm(Are you sure you want to remove this Delegate);">
</asp:LinkButton></span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我想要做的是显示一个确认框如果用户按下开启按钮服务器端代码(即:行命令)事件应该被击中,其他明智的取消它应该什么都不做。但它不起作用。
答案 0 :(得分:1)
confirm()
功能的代码无效。
confirm()
需要一个字符串变量(see window.confirm)但在你的情况下,你传入的是一个无效的对象,并会收到错误
未捕获的SyntaxError:意外的标识符
更新您的代码;
<asp:LinkButton
ID="ImgRemove"
runat="server"
CommandName="Delete"
CommandArgument='<%# Eval("ID") %>'
Text="Remove" OnClientClick="return confirm('Are you sure you want to remove this Delegate');">
答案 1 :(得分:0)
我的建议是将单引号添加到OnClientClick
OnClientClick="return confirm('Are you sure you want to remove this Delegate');
您还可以尝试以下代码:
OnClientClick="if (!confirm('Are you sure you want to remove this Delegate')) return false;"
答案 2 :(得分:0)
尝试以下代码段。
<asp:LinkButton ID="ImgRemove" runat="server" CommandName="Delete" CommandArgument='<%# Eval("ID") %>' Text="Remove" OnClientClick="if (!confirm('Are you sure you want to remove this Delegate?'));">
OnClientClick="if (!confirm('Are you sure you want to remove this Delegate?'));