Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello.
I have an problem using my jquery UI dialog. If i click ones, it open perfect, but second time it opens twice and so on. I found different solutions. No have worked. Please help me
HTML
<a class="openLoginDialog" data-dialog-id="LoginDialog" data-dialog-title="Login" href="@Url.Action("LogOn", "Authentication", new { returnUrl = Request.Url.ToString() })">@Oline.Portal.Resources.Resources._headerlogin</a>

JavaScript
$(".openLoginDialog").on("click", function (e) {
  e.preventDefault();
  $("<div></div>")
    .addClass("dialog")
    .attr("id", $(this).attr("data-dialog-id"))
    .appendTo("body")
    .dialog({
      title: $(this).attr("data-dialog-title"),
      create: function (event, ui) {},
      close: function () { $(this).remove() },
      open: function (event, ui) {},
      modal: true,
      position: ['center', 130],
      minWidth: 510,
      resizable: true,
      zIndex: 20000
    })
    .load(this.href);
});
Posted

1 solution

Probably you are not closing the opened dialog properly...

In the above code you are creating dialog dynamically in each click event. So you should destroy(or delete) it before clicking to open it again.
Means on click of close delete the dialog.

Hope this is the case in your code...
 
Share this answer
 
Comments
mortenstarck 13-Feb-13 5:07am    
Thanks for that. The solution was to add this two metodes $(this).unbind('click');
$('#openLoginDialog').dialog("destroy"); after e.preventDefault();
vinodkumarnie 13-Feb-13 5:38am    
:-)
Member 10732178 22-Jul-14 3:12am    
thankssss a lot !!
vinodkumarnie 22-Jul-14 9:34am    
Welcome.. Happy coding.. :-)

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