最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - How to close a simple modal dialog on a button click? - Stack Overflow

matteradmin8PV0评论

Here i am trying to close a modal dialog on a button click but it is not closing the dialog.Here is my code

function closemodal() {
    alert("true");
    $.modal.close();
    return false;
}

and

protected void btnOK_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ScriptRegistration", "closemodal();", true);
}

i need to call a javascript function and after that i need to close that dialog..Any suggestion??

EDIT:

  $(document).ready(function () {
        $('#MainContent_uscRetailParameters_btnOK').click(function (e) {
            closemodal();
            return false;
        });
        function closemodal() {
            $.modal.close();
        }
    });

EDIT 2:

  $('#CusCatPOPUP .basic').click(function (e) 
{ 
$('#CusCatPOPUP-content').modal(); 
return false; 
}
); 

Here i am trying to close a modal dialog on a button click but it is not closing the dialog.Here is my code

function closemodal() {
    alert("true");
    $.modal.close();
    return false;
}

and

protected void btnOK_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ScriptRegistration", "closemodal();", true);
}

i need to call a javascript function and after that i need to close that dialog..Any suggestion??

EDIT:

  $(document).ready(function () {
        $('#MainContent_uscRetailParameters_btnOK').click(function (e) {
            closemodal();
            return false;
        });
        function closemodal() {
            $.modal.close();
        }
    });

EDIT 2:

  $('#CusCatPOPUP .basic').click(function (e) 
{ 
$('#CusCatPOPUP-content').modal(); 
return false; 
}
); 
Share Improve this question edited Apr 17, 2012 at 10:03 Rooney asked Apr 17, 2012 at 7:17 RooneyRooney 8477 gold badges15 silver badges21 bronze badges 3
  • Just add the function inside the click function? What modal are you using? – Marco Johannesen Commented Apr 17, 2012 at 7:20
  • ericmmartin./projects/simplemodal – Rooney Commented Apr 17, 2012 at 7:39
  • remember to accept your answers when answered. Can see you have dozen open, which are answered correctly. Else you can't create new threads, and people can't see if the question was answered. – Marco Johannesen Commented Apr 17, 2012 at 8:10
Add a ment  | 

3 Answers 3

Reset to default 2

Unless I'm missing the point:

$('#MainContent_uscRetailParameters_btnOK').click(function (e) {
    MyFunctionCall();   //i.e. call you function here
    $.modal.close();
    return false;
});

Might be an error elsewhere, check your browser console.

Created an example: http://jsfiddle/eTnJF/

With code:

$(document).ready(function() {
    $('.open').click( function() {
        $('#modal').modal();
    });

    $('.close').click( function() {
        closemodal();
        return false;
    });

    function closemodal() {
        alert("true");
        $.modal.close();
    }
});

Which works fine :)

If you want to simply close the modalpopup then the javascript code is.

var mpu = $find('ModalPopupExtender1');
mpu.hide();

Hope it helps.

thanks Kamran

Post a comment

comment list (0)

  1. No comments so far