Rooney
Rooney

Reputation: 847

How to close a simple modal dialog on a button click?

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; 
}
); 

Upvotes: 1

Views: 7981

Answers (3)

Marco Johannesen
Marco Johannesen

Reputation: 13134

Might be an error elsewhere, check your browser console.

Created an example: http://jsfiddle.net/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 :)

Upvotes: 1

Kamran Pervaiz
Kamran Pervaiz

Reputation: 1931

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

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

Hope it helps.

thanks Kamran

Upvotes: 0

Mutation Person
Mutation Person

Reputation: 30498

Unless I'm missing the point:

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

Upvotes: 2

Related Questions