Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
hi, this is my code to open a jquery dialog. it works first time but not second time :( help pls


JavaScript
function LoadGridView(id, row) {
          var dlg = jQuery('#Main_ProductEdit').load('ProductEdit.aspx');

          dlg.dialog({ autoOpen: false, modal: true, show: 'slide', close: 'slide', width: 400, height: 160,
              buttons: { "cancel": function () { dlg.dialog("close");} }
          });
          alert('opening');
          dlg.dialog("open");


      }
Posted
Updated 30-Jun-18 19:32pm
v2

From what I can see, there seems to be some sort of a conflict between the JQuery 'load' and the 'dialog' functions. Do you really need to be adding the dialog to the element every time this function is called?

The following works in my browser.

Javascript:
JavaScript
// this var needs to be global
var dlg;

$(document).ready(function () {

    // grab the element
    dlg = $("[id$='Main_ProductEdit']");

    // add the dialog function to it
    dlg.dialog({ autoOpen: false, modal: true, show: 'slide', close: 'slide', width: 400, height: 160,
        buttons: { "cancel": function () { dlg.dialog("close"); } }
    });

});

function LoadGridView() {

    // load contents
    dlg.load('ProductEdit.aspx');

    // open it
    dlg.dialog("open");
}


HTML:
HTML
<input type="button" value="Open" onclick="LoadGridView();"/>
 
Share this answer
 
v3
Comments
Faisalabadians 26-Dec-12 0:24am    
Nick Fisher you are such a great man... thanks a lot dear... may you live long and be happy always..
Faisalabadians 26-Dec-12 0:32am    
can you tell me one thing more? how to load another .aspx page in jquery dialoge for the above same problem?
JavaScript
function PopupForm(url) {
    var formDiv = $('#dialog');
    $.get(url)
        .done(function (response) {
            formDiv.html(response);
            Popup = formDiv.dialog({
                autoOpen: true,
                resizable: false,
                modal: true,
                close: 'slide',
                title: 'Add Details',
                height: 200,
                width: 300,
                close: function () {
                    var url = 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js';
                    var script = document.createElement("script")
                    script.type = "text/javascript";
                    script.src = url;
                    document.getElementsByTagName("head")[0].appendChild(script);
                },
            });
        });
}
 
Share this answer
 
v2
Comments
CHill60 2-Jul-18 5:13am    
Just dumping code against a 6 year old question does not constitute a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900