C# 在asp.net中创建多个Jquery对话框

C# 在asp.net中创建多个Jquery对话框,c#,jquery,asp.net,jquery-ui,jquery-dialog,C#,Jquery,Asp.net,Jquery Ui,Jquery Dialog,我正在尝试创建多个对话框,有些我无法理解如何创建这些对话框 我为每个对话框设置了DIV,其中每个操作都有一条消息。基本上,如果用户选中复选框,则会出现一个对话框,说明您要确认此操作。一段时间后,如果用户再次取消选中复选框,则会出现另一个对话框,其中包含diff消息。请帮我拿这个 这是我到目前为止得到的 =============== HTML ===================== 我想要执行的代码 这里的问题是dialog从未出现,因为当页面加载时,我的所有div都可见,因为我无法在页面加

我正在尝试创建多个对话框,有些我无法理解如何创建这些对话框

我为每个对话框设置了
DIV
,其中每个操作都有一条消息。基本上,如果用户选中
复选框
,则会出现一个对话框,说明您要确认此操作。一段时间后,如果用户再次取消选中
复选框
,则会出现另一个对话框,其中包含diff消息。请帮我拿这个

这是我到目前为止得到的

===============

HTML =====================

我想要执行的代码 这里的问题是dialog从未出现,因为当页面加载时,我的所有div都可见,因为我无法在页面加载时设置
dialogID
变量。此外,我在这个页面上至少有5个对话框可以实现相同的功能。如果您能建议更好的方法或告诉我我在这里做错了什么,我将不胜感激

谢谢,
Milan P

您的方法的另一个可能的问题是jQuery对话框是异步的,这意味着

if(!result)
将在用户有时间确认或取消对话框之前很久进行评估。如果您想要模拟javascript的行为,请使用对话框确认,您需要使用jQuery延迟对象。此外,我建议根据需要创建和销毁对话框,例如:

function confirmDialog(msg) {
    var dialog = $("<div>"+msg+"</div>");
    var def = $.Deferred();

    $(dialog).dialog({
        autoOpen: true,
        width: 300,
        height: 200,
        resizable: false,
        modal: false,
        buttons: {
            'Confirm': function() {
                def.resolve();
                $( this ).dialog( "close" );
            },
            'Cancel': function() {
                def.reject();
                $( this ).dialog( "close" );
            }
        },
        close: function () {
            if (def.state() === "pending") {
                def.reject(); // Make sure unanswered dialog rejects
            }

            $( this ).remove();
        }
    });
    return def.promise();
}
阅读更多关于jQuery的信息

小提琴:


编辑:固定代码,添加小提琴

为什么不保留一个div和一个对话框,并动态更改内容?啊。。但是我不知道怎么做。只需创建一个对话框,并根据您的条件使用$(“#id_of your_dialog”).html(“您要显示的内容”)设置内容;看起来你击中了正确的岩石。。。让我试试这个,我也会看看你提供的更多信息的链接+1用于动态生成DIV的。。。Ohhhh我喜欢Jquery…#修复了close上缺少的“function()”,添加了一个fiddle。你能帮我看看这把小提琴吗?我还得按两下按钮才能关闭对话框@patel.milanb该小提琴上的jquery在toLowerCase函数上出现异常,通过一些小的改进修复了你的小提琴(this.checked而不是$(this.is(“:checked”):PS:你可能想试着找出为什么你的小提琴帐户在toLowerCase javascript函数上遇到问题:)哦,对不起,如果没有阅读确认消息,请尝试最重要的更改是对话框外部的“var that=this”,因为上下文内部发生更改(“this”将不再指复选框)。请注意,如果不需要,可以删除整个.done()块。
$(document).on("change",isReceivedCheckBox, function () {
var checked = $(this).is(':checked');
if (checked) {
  dialogId = "'#dialog-isReceived'"; //setting the DIV ID here and hoping that dialog will appears.
  $(dialogId).dialog('open');
  if(!result)
        $(this).attr("checked", false); // if user clicks cancel on dialog then do not check the checkbox
} else {
    dialogId = "'#dialog-notReceived'";
    $(dialogId).dialog('open');
  if(!result)
        $(this).attr("checked", true); //if user clicks cancel on dialog then do not uncheck the checkbox because it was checked previously
}
});
if(!result)
function confirmDialog(msg) {
    var dialog = $("<div>"+msg+"</div>");
    var def = $.Deferred();

    $(dialog).dialog({
        autoOpen: true,
        width: 300,
        height: 200,
        resizable: false,
        modal: false,
        buttons: {
            'Confirm': function() {
                def.resolve();
                $( this ).dialog( "close" );
            },
            'Cancel': function() {
                def.reject();
                $( this ).dialog( "close" );
            }
        },
        close: function () {
            if (def.state() === "pending") {
                def.reject(); // Make sure unanswered dialog rejects
            }

            $( this ).remove();
        }
    });
    return def.promise();
}
confirmDialog("are your sure?").done(function() {
    // He/She said yes
}).fail(function() {
    // He/She said no
});