在删除转发器中的行之前,我想要验证,确定要删除..?我该怎么做?

时间:2012-03-22 07:48:03

标签: asp.net repeater

我想做验证,确定要删除..?

<asp:LinkButton ID="lnkDelete" runat="server"  
           CommandName='<%# DataBinder.Eval(Container.DataItem, "ImageId") %>' OnCommand="Calling_Delete">Delete</asp:LinkButton> 

4 个答案:

答案 0 :(得分:1)

最简单的方法是使用确认按钮扩展器。只需将此控件拖到linkbutton旁边,然后将Confirmbutton externders TargetControlID设置为Linkbutton的Id。其他一切都将由控件处理。

更多信息 - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ConfirmButton/ConfirmButton.aspx

答案 1 :(得分:0)

This answer有一种方法可以使用jQuery和a jQuery UI dialog

使用jQuery UI提供的javascript对话框的一个优点是弹出对话框仅对显示它的网页是模态的。在弹出窗口显示时,您仍然可以访问浏览器中的其他选项卡。

使用javascript confirm函数的其他解决方案将强制用户在切换到其他浏览器标签之前关闭确认对话框。

答案 2 :(得分:0)

使用OnClientClick属性附加将执行提示的java脚本。例如,

<asp:LinkButton ID="lnkDelete" runat="server" 
     CommandName='<%# DataBinder.Eval(Container.DataItem, "ImageId") %>' 
     OnClientClick="return confirm('Are sure you want to delete..?');"
     OnCommand="Calling_Delete">Delete</asp:LinkButton>

答案 3 :(得分:0)

如果您想使用自定义确认(如jquery对话框,bootboxjs等),那么您必须生成按钮的“回发字符串”或以某种方式获取它。 asp.net在呈现页面后给出诸如回发名称;的 __ doPostBack( 'ctl00 $ $ ContentPlaceHolder1 btnDeleteSelected', '')即可。在意识到这一点之后我写了一个js函数,它生成了button的postback str;

function PostBackBtnMake(id) { // id : ContentPlaceHolder1_btnDeleteSelected
var result;
var temp = id.split('_');
result = 'ctl00$' + temp[0] + '$' + temp[1];
return result;

}

然后我可以在自定义确认框中使用(在本例中我使用了bootboxjs);

function PostBackBtn(e) {
var _result = false;
bootbox.confirm("Are you sure?", function (result) {
    if (result) {
        __doPostBack(PostBackBtnMake(e.id), '')
    }
});

return _result;

}

它对我有用,我希望它对你也有帮助。

相关问题