Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3227944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:38:02+00:00 2026-05-17T16:38:02+00:00

I have made a generic function to show jQuery dialogs in my app. this

  • 0

I have made a generic function to show jQuery dialogs in my app. this function simply

  • Set the dialog title
  • make an ajax call to a server side function and populate the dialog with the html returned
  • open the dialog

Here is the function:

function loadDialog(action, id, title, onCloseHandler) {
    $("#__gsl_DialogPanel").dialog("option", "title", title);
    var url = action;
    if (id != "") url = url + "/" + id;
    $.ajax({
        type: "get",
        dataType: "html",
        url: url,
        data: {},
        success: function(response) {
            $("#__gsl_DialogPanel").html('').html(response).dialog('open');
        }
    });
    $("#__gsl_DialogPanel").bind("dialogclose", function(event, ui) {
        if (onCloseHandler != null)
            onCloseHandler();
    });
}

As you can see the function actually does even bind a function to the dialogclose event so when the dialog is closed that function get called. This feature is particularly useful if I use a dialog to add/edit/delete elements in a grid: I can pass a function that does a grid update and when the dialog is closed the grid will update itself.

I am experiencing that, in some cases, the function binded to the dialogclose event is called more than once and I am suspecting that the problem is related to the fact that multiple calls to my loadDialog function will bind multiple reference of the same close handler.

Am I correct? Do I have to explicitly unbind everything whn the dialog close?

thanks for helping!

Update:

As per the answers received I have simply unbinded and binded again the function handler and everything works! this is the updated code

$("#__gsl_DialogPanel").unbind("dialogclose").bind("dialogclose", function(event, ui) {
    if (onCloseHandler != null)
        onCloseHandler();
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:38:03+00:00Added an answer on May 17, 2026 at 4:38 pm

    jQuery has a nice syntax for custom events: 'eventName.pluginName'
    This way you can bind the same event, but differentiate between the different handlers.

    calling trigger('eventName') will trigger all handlers

    In your case you can unbind just your event, and leave others alone.

    Example:

    <input id="btn" type="button" value="Button">
    

    Javascript:

    $('#btn'​).​bind('myEvent',function(){
        alert('myEvent.other plugins');
    });
    
    $('#btn').bind('myEvent.myPlugin',function(){
        alert('myEvent.myPlugin');
    });
    
    //use this in your loadDialog function for the dialogClose event
    $('#btn').unbind('myEvent.myPlugin').bind('myEvent.myPlugin',function(){
        alert('myEvent.myPlugin');
    });
    
    $('#btn').trigger('myEvent');
    ​
    

    You can try this live jsFiddle example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a generic PHP script to use for an AJAX call. I
I am making a generic text validation function with jQuery. I made the function
I have a generic function for XMLHttpRequests. as follows: function XMLRequest(address, data){ this.html =
I have made a generic Observer interface and an Observable class, but can't compile
I have made a jQuery toggle for a menu that I had in mind.
I have made an application for IPad in objective C. In this I am
I have a generic collection MyCollection<T> that I've made, and everything works fine except
I would have made the title more specific but I don't know how to
i have to do a generic double linked list, and i made it in
I have made a generic parser for parsing ascii files. When I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.