views:

142

answers:

1

i have such a function when it is invoked a dialog is created, after the dialog is closed and the button is clicked again, the dialog doesn't showup

$("#Button").click(function() {
                $.ui.dialog.defaults.bgiframe = true;
                                $("#box").dialog({
                                    modal: true,
                                    draggable: true,
                                    width: 600  
                                });
                               });

whats wrong here?

+2  A: 

Use something like this:

$( document ).ready ( function () {
    $.ui.dialog.defaults.bgiframe = true;
    $( "#box" ).dialog ( {
        modal: true,
        autoOpen: false,
        draggable: true,
        width: 600  
    } );

    $( '#Button' ).click ( function () {
        $( '#box' ).dialog ( 'open' );
    } );
} );

The catch is that you only init the dialog once, and then call .dialog ( 'open' ), when you actually want to open the dialog

Jan Hančič
+1: Nice answer. But I don't see why that is the **catch**. You make it sound like something wrong that he has to live with! Its a good way to reuse the dialog.
Senthil
the catch was in reference to the OP's code :)
Jan Hančič
thanks, helped a lot
CoffeeCode