.net c# OnClientClick 返回确认后 OnCommand 未触发

OnCommand Not Firing After OnClientClick return confirm
2021-11-25
  •  译文(汉语)
  •  原文(英语)

我有这个运行良好的删除功能.想在用户决定删除之前添加确认,但现在用户从确认框中返回 OK 后,我的删除将不起作用.

HTML:

<div>
    <asp:Button ID="btnDelete" UseSubmitBehavior="false" runat="server" Text="Remove" 
        CssClass="appdl" CommandName="Remove" OnCommand="AppsList_ItemCommand" 
        OnClientClick="return confirm('Are you certain you want to delete?');"
        CommandArgument='<%# Eval("ID") %>' />
</div>

正如您在上面的 HTML 中看到的,我使用 OnCommand 来执行删除功能.在我添加 OnClientClick 之后,OnCommand 似乎停止触发,即使在我单击确定之后.不太确定出了什么问题.任何指针将不胜感激.

解决过程1

UseSubmitBehavior="false"从您的标记中删除并尝试

解决过程2
function conformbox()
{
var con=confirm("Are you sure want to delete?");
if(con==true)
{
return true;
}
else
{
return false;}
}

-------------///*//----------------

<asp:Button ID="deleteBtn" runat="server" Text="Delete User" OnClientClick="return         
conformbox();" /><br />

检查返回值(真或假)

解决过程3

试试这个

<div>
    <span onclick="return confirm('Are you certain you want to delete?');">
       <asp:Button ID="btnDelete" UseSubmitBehavior="false" runat="server" Text="Remove" 
            CssClass="appdl" CommandName="Remove" OnCommand="AppsList_ItemCommand"         
            CommandArgument='<%# Eval("ID") %>' />
      </span>
<div/>

I have this delete function that was working perfectly fine. Wanted to add a confirmation right before the user decides to delete it, but now my delete won't work after the user returns OK from the confirmation box.

HTML:

<div>
    <asp:Button ID="btnDelete" UseSubmitBehavior="false" runat="server" Text="Remove" 
        CssClass="appdl" CommandName="Remove" OnCommand="AppsList_ItemCommand" 
        OnClientClick="return confirm('Are you certain you want to delete?');"
        CommandArgument='<%# Eval("ID") %>' />
</div>

As you can see in the HTML above, I'm using OnCommand to perform the delete function. After I added in OnClientClick, OnCommand seems to stop firing, even after I click OK. Not really sure what's wrong. Any pointer would be very much appreciated.

Solutions1

remove UseSubmitBehavior="false" from your mark up and the try

Solutions2
function conformbox()
{
var con=confirm("Are you sure want to delete?");
if(con==true)
{
return true;
}
else
{
return false;}
}

-------------//*//----------------

<asp:Button ID="deleteBtn" runat="server" Text="Delete User" OnClientClick="return         
conformbox();" /><br />

check the return values (true or false)

Solutions3

Try this one

<div>
    <span onclick="return confirm('Are you certain you want to delete?');">
       <asp:Button ID="btnDelete" UseSubmitBehavior="false" runat="server" Text="Remove" 
            CssClass="appdl" CommandName="Remove" OnCommand="AppsList_ItemCommand"         
            CommandArgument='<%# Eval("ID") %>' />
      </span>
<div/>
转载于:https://stackoverflow.com/questions/15237759/oncommand-not-firing-after-onclientclick-return-confirm

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入