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 4566626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:48:56+00:00 2026-05-21T18:48:56+00:00

I have a modal popup in my page which closes itself when I click

  • 0

I have a modal popup in my page which closes itself when I click on any control in that dialog, below is the code:

function overlayclickclose() {
    if (closedialog) {
        jQuery('#mydialog').dialog('close');
    }
}
closedialog = 1;

jQuery('#mydialog').dialog({
    bgiframe: true,
    autoOpen: false,
    modal: true,
    width: 900,
    height: 400,
    resizable: false,
    open: function() {
        closedialog = 1;
        jQuery(document).bind('click', overlayclickclose);
    },
    focus: function() {
        closedialog = 1;
    },
    close: function() {
        jQuery(document).unbind('click');
    }
});

When I click on that modal dialog anywhere, it closes so I can not operate on it. How can I fix it?

Note that my div is in an update panel and puts a user control of ASP.NET Inside.

  • 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-21T18:48:56+00:00Added an answer on May 21, 2026 at 6:48 pm

    If you want to know why the dialog is closing as soon as you click anywhere in your dialog. You have added a .click() event listener to the whole document, every time a click occurs, it will run your callback function overlayclickclose().

    That is checking to see if you want to close the dialog:

    if (closedialog)
    

    As closedialog is always 1 which as a boolean is true any click anywhere will close the dialog. Your function will basically say if (true) do something, so will always ‘do something’.

    If you change your focus event to:

    closedialog = 0;
    

    Close dialog is now 0 which as a boolean is flase so the dialog wont close.

    See it working here

    See it not working as you have it here


    After a quick search, it looks like the code you are using is something very similar to this tutorial – see the use of 1 and 0 for the closedialog variable.


    There is another way you can do this, its probably easier to follow in code. See the question here. You can change your code to something like this:

    $('#mydialog').dialog({
        bgiframe: true,
        autoOpen: true,
        modal: true,
        width: 300,
        height: 200,
        resizable: false
    });
    
    $('.ui-widget-overlay').live('click', function() {
        $('#mydialog').dialog('close');
    }); 
    

    See it working here

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

Sidebar

Related Questions

I have an ajax control toolkit modal popup on my page and in that
I have an ajax modal popup, which is shown on click of a button
I have a JInternalFrame window that needs to popup a modal dialog box when
I created a Simply Modal popup dialog which works fine if you click on
I have a modal popup extender which is triggered by gridview onRowCommand. The gridview
I have a modal popup with several links inside that have the :confirm and
I have a gridview that is only shown in a modal popup. right before
I'm using ajax requests to populate modal popup windows with data that users have
I have a page with a user control which gets some data updated via
I have a page (page1), which loads a different page (page2) into a modal

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.