我有一个jQuery UI对话框工作在我的ASP。NET页面:

jQuery(function() {
    jQuery("#dialog").dialog({
        draggable: true,
        resizable: true,
        show: 'Transfer',
        hide: 'Transfer',
        width: 320,
        autoOpen: false,
        minHeight: 10,
        minwidth: 10
    });
});

jQuery(document).ready(function() {
    jQuery("#button_id").click(function(e) {
        jQuery('#dialog').dialog('option', 'position', [e.pageX + 10, e.pageY + 10]);
        jQuery('#dialog').dialog('open');
    });
});

我的div。

<div id="dialog" style="text-align: left;display: none;">
    <asp:Button ID="btnButton" runat="server" Text="Button" onclick="btnButton_Click" />
</div>

但是btnButton_Click从来没有被调用…我怎么解决这个问题呢?

更多信息:我添加了这段代码来移动div到窗体:

jQuery("#dialog").parent().appendTo(jQuery("form:first"));

但还是没有成功……


当前回答

这对我来说是最明确的解决方案

var dlg2 = $('#dialog2').dialog({
        position: "center",
        autoOpen: false,
        width: 600,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
            },
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });

dlg2.parent().appendTo('form:first');
$('#dialog_link2').click(function(){
    dlg2.dialog('open');

dlg2中的所有内容都可以插入到数据库中。不要忘记更改对话框变量以匹配您的。

其他回答

这主要是因为jQuery使用DOM将对话框移到表单标记之外。将其移回表单标签内,应该可以正常工作。您可以通过检查Firefox中的元素来看到这一点。

$('#dialog').parent(). appendto ($("form:first"))解决方案在IE 9中正常工作。但是在ie8中,它可以让对话框直接出现和消失。你不能看到这个,除非你放置一些警告,这样对话框似乎永远不会出现。 我花了一个上午的时间找到了一个在两个版本都适用的解决方案,而在版本8和9上都适用的唯一解决方案是:

$(".ui-dialog").prependTo("form");

希望这能帮助其他有同样问题的人

Robert MacLean给出的答案有99%的正确率。但是,像我这样的人可能需要添加的唯一内容是,每当需要打开这个jQuery对话框时,不要忘记将它附加到parent。像下图:

var dlg = $('#questionPopup')。对话框(“开放”); dlg.parent () .appendTo($(“形式:第一”));

这对我来说是最明确的解决方案

var dlg2 = $('#dialog2').dialog({
        position: "center",
        autoOpen: false,
        width: 600,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
            },
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });

dlg2.parent().appendTo('form:first');
$('#dialog_link2').click(function(){
    dlg2.dialog('open');

dlg2中的所有内容都可以插入到数据库中。不要忘记更改对话框变量以匹配您的。

顺便说一句,第一个技巧对我没用。

然而,那篇博客文章中的技巧做到了:

http://blog.roonga.com.au/2009/07/using-jquery-ui-dialog-with-aspnet-and.html

具体来说,将这个添加到对话框声明中:

  open: function(type,data) {
    $(this).parent().appendTo("form");
  }