确认回发OnClientClick按钮ASP

确认回发OnClientClick按钮ASP

<asp:Button runat="server" ID="btnUserDelete" Text="Delete" CssClass="GreenLightButton"
                           OnClick="BtnUserDelete_Click"
                           OnClientClick="return UserDeleteConfirmation();"
 meta:resourcekey="BtnUserDeleteResource1" />

我试过了:
function UserDeleteConfirmation() {
        if (confirm("Are you sure you want to delete this user?"))
            return true;
        else
            return false;
}


function UserDeleteConfirmation() {
    if (confirm("Are you sure you want to delete this user?")) {
            __doPostBack(btnUserDelete, '');
    }

    return false;
 }

而且它们都不起作用。

最佳答案

试试这个:

<asp:Button runat="server" ID="btnUserDelete" Text="Delete" CssClass="GreenLightButton"
                       OnClick="BtnUserDelete_Click"
                       OnClientClick="if ( ! UserDeleteConfirmation()) return false;"
 meta:resourcekey="BtnUserDeleteResource1" />

这样,仅当用户单击“取消”时才执行“返回”,而不是在用户单击“确定”时才执行。

顺便说一句,您可以将UserDeleteConfirmation函数缩短为:
function UserDeleteConfirmation() {
    return confirm("Are you sure you want to delete this user?");
}

关于javascript - 确认回发OnClientClick按钮ASP.NET,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14058116/

10-10 18:57