确认模式按钮 asp.net 的操作

Confirm action for modal button asp.net

本文关键字:操作 net asp 模式 按钮 确认      更新时间:2023-09-26

当用户单击下面模式上的"取消"按钮时,我正在尝试添加提示。它会提示他们确认操作。下面的代码是我目前尝试的代码。

function ShowAddEditExecutive() {
        $("#addEditExecutive").dialog({
            modal: true,
            width: 800,
            appendTo: "form",
            open: function () {
                $(this).dialog("widget").find(".ui-dialog-titlebar").show();
                // Removes the do you want to leave this page dialog.
                window.onbeforeunload = null;
                // The two isplalines below are 2 different ways to ensure the 
                // background is completely grayed out if the modal is larger
                // then the page. The first was chosen so that the scroll
                // bars are not disabled.
                $('.ui-widget-overlay').css('position', 'fixed');
               //$('body').css('overflow', 'hidden');
            },
            buttons: {
                "Add/Edit Executive Information": function () {
                    $("[id*=btnAddEditExecutive]").click();
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
             },
        close: function (ev, ui) {
            // Ensures when you cancel that the values are not retained.
            $(this).remove();
            // The two lines below are 2 different ways to ensure the 
            // background is completely grayed out if the modal is larger
            // then the page. The first was chosen so that the scroll
            // bars are not disabled.
            $('.ui-widget-overlay').css('position', 'absolute');
            //$('body').css('overflow', 'inline');
        },
    });

    }

如果要创建本机方法来确认操作,可以使用confirm提示用户选择继续或不继续,这是您应该在代码中执行的操作

"Cancel": function () {
    if(confirm("Are you sure you want to cancel ?"))
    {
        //code if yes
        $(this).dialog("close");
    }
    else
    {
        //code if no, don't do anything in your case, or don't use the else
    }
}

下面是使用示例。

另一种方式,如果你想让它看起来与你的设计相同,你可以创建一个自定义<div>,其中包含用户是否同意或想要继续的确认文本,然后使用CSS并使用jQuery onclick function来处理事件style它。