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

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

Question

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
Was it helpful?

Solution 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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top