JavaScript runtime error: can't call methods on dialog prior to initialization; tried to call 'close'

StackOverflow https://stackoverflow.com/questions/23296624

문제

I am new to Javascript. I am using jQuery 1.11.0 and jQuery UI 1.10.4 and a plugin mask. I call the function closeDialog in code behind. I am getting the error 0x800a139e - JavaScript runtime error: cannot call methods on dialog prior to initialization; attempted to call method 'close'. I have searched all over but to no avail. How do I initialize the dialog? Any help is appreciated.

<script type="text/javascript">
$(document).ready(function () {
    $("#tabs").tabs()

    var source = $("#dialog").parent()

    $("#dialog").dialog({
        //autoOpen: true,
        height: 130,
        width: 325,
        open: function (type, data) {
            $(this).parent().appendTo(source)
        },
        close: function (type, data) {
            $(this).remove()
        }
    })

    $(".datepicker").datepicker() 

    $(".phonenumber").mask("(999) 999-9999")

    $(".zipcode").mask("00000-0000")

})

function closeDialog() {
    $("#dialog").dialog("close")
}

function disableTabs() {
    $("#tabs").tabs({
        disabled: [1, 2]
    })
}

function enableTabs() {
    $("#tabs").tabs({
        disabled: []
    })
}

function alertBox() {
    alert("Please choose a valid selection.")
}

 Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
   If Not Page.IsPostBack Then
           Dim script As String = "closeDialog();"
           ScriptManager.RegisterStartupScript(Me, Me.GetType(), "CloseDialog", script, True)
        End If
    End If
End Sub
도움이 되었습니까?

해결책 2

pageLoad() method is called each and every partial postback of update panel but $(document).ready() is not called each and every partial postback of update panel. $(document).ready() is called only one time (during first time of page loading). Hence code written in $(document).ready() method will not be initialized each and every partial postback.

다른 팁

It looks like your closeDialog function is getting called before document's ready event. Try to use ScriptManager.RegisterClientScriptBlock method instead of ScriptManager.RegisterStartupScript.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top