Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
回发后关闭JQuery对话框iframe内的asp.net表单时发生Javascript错误_Jquery_Asp.net_Iframe - Fatal编程技术网

回发后关闭JQuery对话框iframe内的asp.net表单时发生Javascript错误

回发后关闭JQuery对话框iframe内的asp.net表单时发生Javascript错误,jquery,asp.net,iframe,Jquery,Asp.net,Iframe,我有一个aspx页面,我将其加载到通过JQuery对话框显示的iframe中。该页面有一个取消按钮,该按钮调用一个“CloseMe”脚本,该脚本成功关闭JQuery对话框。该页面还有一个“保存”按钮,可以发回。保存数据后,我想关闭对话框 我已尝试注册一个启动脚本,该脚本在document.ready上调用“CloseMe”函数。当我这样做时,代码开始在JQuery中抛出毫无意义的javascript错误。比如“数组未定义”、“函数未定义”和“日期未定义”。编辑:它在点击“window.paren

我有一个aspx页面,我将其加载到通过JQuery对话框显示的iframe中。该页面有一个取消按钮,该按钮调用一个“CloseMe”脚本,该脚本成功关闭JQuery对话框。该页面还有一个“保存”按钮,可以发回。保存数据后,我想关闭对话框

我已尝试注册一个启动脚本,该脚本在document.ready上调用“CloseMe”函数。当我这样做时,代码开始在JQuery中抛出毫无意义的javascript错误。比如“数组未定义”、“函数未定义”和“日期未定义”。编辑:它在点击“window.parent.$…(close)语句时执行此操作。请注意该行前面的警报。它正确报告iframe的id

我在“取消”按钮上使用相同的“关闭我”功能,一切正常

编辑:在忽略调试器中所有25个左右的错误后,对话框将关闭

以下是打开对话框的javascript:

function jQueryShowiFrame(url, title, reloadOnClose) {

    $('<iframe id="modalIframeId" allowtransparency="true" frameborder="0" src="' + url + '" />').load(function () {

        var width = $("#modalIframeId").contents().width();
        var height = $("#modalIframeId").contents().height();
        var paddingWidth = parseInt($("#modalIframeId").css("padding-left"), 10) + parseInt($("#modalIframeId").css("padding-right"), 10);

        // the sequence of these steps is important
        $("#modalIframeId").dialog("option", "width", (width + paddingWidth) + 'px');

        this.style.width = width + 'px';
        this.style.height = height + 'px';

        $("#modalIframeId").dialog("option", "position", "center");
    })
    .dialog({
        title: title,
        modal: true,
        close: function (ev, ui) {
            $(this).dialog('destroy').remove();
            if (reloadOnClose) {
                location.reload();
            }
        },
        open: function (ev, ui) {
            //alert('x');
        }
    });
}
函数jQueryShowiFrame(url、标题、重载关闭){
$('').load(函数(){
变量宽度=$(“#modalIframeId”).contents().width();
var height=$(“#modalIframeId”).contents().height();
var paddingWidth=parseInt($(“#modalIframeId”).css(“左填充”),10)+parseInt($(“#modalIframeId”).css(“右填充”),10);
//这些步骤的顺序很重要
$(“#modalIframeId”)。对话框(“选项”、“宽度”、“宽度+填充宽度)+“px”);
this.style.width=宽度+px;
this.style.height=高度+px;
$(“#modalIframeId”)。对话框(“选项”、“位置”、“中心”);
})
.对话({
标题:标题,,
莫代尔:是的,
/*添加属性*/
autoOpen:false,/*而不是调用“CloseMe”*/
关闭:功能(ev、ui){
$(this.dialog('destroy').remove();
如果(重新加载关闭){
location.reload();
}
},
打开:功能(ev、ui){
//警报('x');
}
});
}
使用
autoOpen:false
可防止启动时打开对话框。请使用该对话框,而不是调用
CloseMe
函数


希望有帮助。

可能是在创建
frameElement.id
之前您正在访问它。但是在关闭按钮中
CloseMe
工作正常,因为
frameElement
已创建。我想到了这一点。但是当我输入“警报(window.frameElement.id)”;“语句,它会以正确的id响应。Gokul-感谢您快速响应。可能我不清楚。jQueryShowiFrame()只是最初加载iframe的函数。它不会再次被调用。因此我无法从iframe中的页面重新调用它。也许我甚至不应该包含它。我只是想完整。
<asp:Button ID="btnSave" runat="server" CssClass="BasicButton" Text="Save" />
<button type="button" id="btnClose" onclick="closeMe()" >Cancel</button>

<script type="text/javascript">

    function closeMe() {
        alert(window.frameElement.id);
        window.parent.$('#' + window.frameElement.id).dialog('close');
    }
</script>
Dim scr As String = "$(document).ready(function () { closeMe(); });"
ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), Guid.NewGuid.ToString, scr, True)
function jQueryShowiFrame(url, title, reloadOnClose) {

    $('<iframe id="modalIframeId" allowtransparency="true" frameborder="0" src="' + url + '" />').load(function () {

        var width = $("#modalIframeId").contents().width();
        var height = $("#modalIframeId").contents().height();
        var paddingWidth = parseInt($("#modalIframeId").css("padding-left"), 10) + parseInt($("#modalIframeId").css("padding-right"), 10);

        // the sequence of these steps is important
        $("#modalIframeId").dialog("option", "width", (width + paddingWidth) + 'px');

        this.style.width = width + 'px';
        this.style.height = height + 'px';

        $("#modalIframeId").dialog("option", "position", "center");
    })
    .dialog({
        title: title,
        modal: true,
        /*Add a Property */
        autoOpen : false, /* Instead of Calling 'CloseMe' */
        close: function (ev, ui) {
            $(this).dialog('destroy').remove();
            if (reloadOnClose) {
                location.reload();
            }
        },
        open: function (ev, ui) {
            //alert('x');
        }
    });
}