确认对话框没有在asp.net中文件itemCommand
本文关键字:net 中文 文件 itemCommand asp 对话框 确认 | 更新日期: 2023-09-27 18:13:25
我正在使用asp.net 4.5和c#。从中继器上删除命令,我要显示确认对话框。如果用户按"是",则删除该记录。我的删除逻辑是在"rep_ItemCommand"事件。这是我的代码
<as:Pager ID="pgeImportedFiles" AutoPostBack="True" EnableViewState="true" runat="server" RepeaterControlID="rptImportFiledata" Visible="false" PageSize="10" DisplayPagerOption="Top">
<RepeaterTemplate>
<asp:Repeater ID="rptdata" EnableViewState="true" runat="server" OnItemCommand="rptdata_ItemCommand" >
<ItemTemplate>
<div >
<asp:LinkButton ID="lbnDelete"
OnClientClick="javascript:return showConfirmation('Are you sure You want to Delete this File?',this.id);"
runat="server" CommandName="Delete" CssClass="EditBtn" CommandArgument='<%# Eval("ID") %>'>Delete</asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>
</RepeaterTemplate>
</as:Pager>
protected void rptdata_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//logic for deleteing
}
这个javascript在js文件和"divDialogMessage1"answers"divAlertBox1"定义在这个文件
$(divDialogMessage1).html(confirmationMessage,uniqueID){
var result = false;
$(divAlertBox1).dialog({
title: "Confirmation",
buttons: {
"Yes": function () {
__doPostBack(uniqueID);
$(this).dialog("close");
},
"No": function () {
$(this).dialog("close");
}
}
});
$(divAlertBox1).dialog('open');
return result;}
通过这个对话框显示在点击删除链接和页面也张贴回来,如果选择"是"选项。但是rptdata_ItemCommand没有触发。
有解决方案吗?
删除逻辑
protected void rptdata_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//logic for deleteing
switch (e.CommandName)
{
case "edit":
MyEditFunction(e.CommandArgument.ToString());
break;
case "delete":
MyDeleteFunction(Convert.ToInt32(e.CommandArgument));
break;
}
}
确认消息
将OnItemDataBound=" adddeletecconfirm "添加到您的中继器标记中,并在
后面的代码中添加以下代码protected void AddDeleteConfirmation(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{
// adds a confirmation javascript to ensure that deleting the template is really what the user wants.
((LinkButton)e.Item.FindControl("lbnDelete")).Attributes["onclick"] = "javascript: return confirm('Are you sure you want to delete this record?')";
}
}