Closing a Modal Popup from a

Closing a Modal Popup from a

I have this code:
  1. <link href="" rel="stylesheet" type="text/css"/>
    <script src=""></script>
    <script src=""></script>
    <script type="text/javascript">
        function ShowPopup(message) {
            var _dialog;
            $(function () {
                var iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0" src="clienti.aspx" width="680" height="460" allowfullscreen></iframe>');
                   _dialog = $("<div></div>").append(iframe).appendTo("body").dialog({
                    autoOpen: true,
                    modal: true,
                    resizable: false,
                    width: "720",
                    height: "520",
                    close: function () {
                        iframe.attr("src", "");
                modal: true
        function CloseModal(frameElement) {
            if (frameElement) {
                var dialog = $(frameElement).closest(".modal");
                alert (dialog)
                if (dialog.length > 0) {

I call these functions to open a iframe containing a ASPX page with only a Gridview1 with data and one button for each row. I use this button to select the row and close the iframe by this call:

  1.             If (Not ClientScript.IsStartupScriptRegistered("chiudi1")) Then
                    ClientScript.RegisterStartupScript(Me.GetType(), "chiudi1", " window.parent.CloseModal(window.frameElement);", True)
                End If

I have disseminated alert in CloseModal. The first two are displayed to prove the function is called from the iframe loaded page.but the third is not called, to prove that the modal windows is not found. No action is taken. I don't find any good advice. Can anybody help me?

Thank you very much

Mauro Zanin