views:

37

answers:

2

Im using JQuery dialog and open an iframe inside it in the following way

$('#div1').dialog("destroy");            

if (criteria1== "L") {
    $("#div1").html("<iframe id='dialogFrame1' src='../WebPages/abc.aspx' Height='100%' Width='100%' frameborder='0'></iframe>");
}
else {
    $("#div1").html("<iframe id='dialogFrame2' src='../WebPages/abc1.aspx' Height='100%' Width='100%' frameborder='0'></iframe>");
}

$('#div1').dialog(
  {

      height: 220,
      title: "Title",
      width: 500,
      modal: true,
      beforeclose: function (event, ui) {

          $("#div1").html("");
          $("#div1")[0].innerHTML = "";
      }

  });

$('#div1').parent().appendTo($("form:first"));
$('#div1').dialog('open');

The first time I call dialog("open") it works fine. However, subsequent calls (without a page refresh) show 2 dialogs, 1 a proper one with the controls loaded and another active one that is empty.

Any ideas why?

A: 

ADD this option

autoOpen: false

$('#div1').dialog("destroy");

criteria1="L";
if (criteria1== "L") {
  $("#div1").html("<iframe id='dialogFrame1' src='../WebPages/abc.aspx' Height='100%' Width='100%' frameborder='0'></iframe>");
}
else {
  $("#div1").html("<iframe id='dialogFrame2' src='../WebPages/abc1.aspx' Height='100%' Width='100%' frameborder='0'></iframe>");
}

$('#div1').dialog({
  autoOpen: false, 
  height: 220,
  title: "Title",
  width: 500,
  modal: true,
  beforeclose: function (event, ui) {
    $('#div1').html("");
    $('#div1')[0].innerHTML = "";
  }
});
$('#div1').dialog('open');

$('#div1').parent().appendTo($("form:first"));
JapanPro
Ok. This solved the issue of opening a new dialog as the active one. But now i face a wierd problem. The first time everything works fine. The second time when i open the link corresponding to the else part, it opens a blank dialog though it debugs properly. The 3rd time it works fine. Any views on this pls.
deepa
A: 
$('#div1').parent().appendTo($("form:first"));

i think the above code replicates the content.Change that and test it.

sathis