Jquery -- dialog show() and hide() -


i have .aspx page called default.aspx. using div show dialog, div section is:

   <div id="dialog" class="dialogadd" title="dialog" style="display:none">      ...     </div> 

here jquery call, use show , hide dialog.

     $(document).ready(function () {       function contextmenuaction(){          var key = "add";       if (key == "add") {     $(".dialogadd").dialog({         height: 238,         width: 465,         resizable: false,         title: "add ports"      });          addportcontext($port); // here functionality of adding dialog           }// end of contextmenu              function addportcontext($port) {              $(".dialogadd").show();               $(".imgbtnupdate").click(function () {                  ... // work here                       success: function (jsondata) {             try {                   $(".dialogadd").dialog('close');                    }                   }); // close of click         }); // close of load function 

this how open , close dialog: when click first time, works. second time, not work if not call show(). if use show() in above example, inserted again, , thrice third click.

can 1 please me.

moreover using same div , same functionalty both add , update. same dialog popups add , update, iam unable click second time, or getting inserted each click.

if think closing , opening dialog lot, create toggle function:

var isshown = false; function toggledialog(){     if(!isshown){         $("#dialog").show();         isshown = true;     } else {         $("#dialog").hide();         isshown = false;     } } 

and if wanted fancy, pass in parameter sets message in dialog.

function toggledialog(string message){...     ...     $('#dialog).html(message);     ... } 

even better say, if message passed in, show dialog, otherwise hide it:

function toggledialog(message){     if(message != null){         $('#dialog).html(message);         $("#dialog").show();     } else {         $('#dialog).html("");         $("#dialog").hide();     } } 

then, open toggledialog("cool message"); , close toggledialog(null);


Comments