简体   繁体   中英

Issue with JQuery UI Modal box showing when it shouldn't

So there's a few pieces to this. First of all, here's the Javascript located in the head of the ASPX page:

<!--//**********************************
    // Test modal popup
    //**********************************  -->
<script type="text/javascript">
    //Total out of range dialog
    $(function () {
        $("#dialog").dialog({
            modal: true,
        //    autoOpen: false,
        width: 570,
        buttons: {
            "Ok": function () { $(this).dialog("close"); },
            "Cancel": function () { $(this).dialog("close"); }
        }

        });
    });
</script>

Then, at the very bottom of he ASPX page (which is rather lengthy...) I have the modal piece:

<div id="dialog" title="ATTENTION">
    <table style="width:565px; border-spacing:0px; border-collapse:collapse;">
        <tr>
            <td style="width:65px; ">
                <img src="http://someimage" style="height: 120px; width: 80px" />
            </td>
            <td style="vertical-align:top">
                <p>some text</p>
            </td>
        </tr>
    </table>
</div>

</asp:Content>

Lastly, in the code-behind I have this:

        if (!Page.IsPostBack)
        {
            if (MyServer.Contains("localhost"))
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "dlgOutOfRange", 
                "$(function() {$('#dialog').dialog('open');});", true);
            }

Now, I know this all works, it's been tested. However, this modal is displaying even when it's not supposed to, and when I skip through the code it bypasses the Page.IsPostback so it knows it's not a postback. For instance, I have a dropdown that has a SelectedIndexChange function tied to it. When I change the value in the dropdown, this modal becomes visible. Is there something in the div tag that I'm not doing? I tried adding style="Visible: False;" but that just made the text invisible.

    <script type="text/javascript">
$(document).ready(function () {
    $("#dialog").dialog({
        modal: true,       
    width: 570,
    buttons: {
        "Ok": function () { $(this).dialog("close"); },
        "Cancel": function () { $(this).dialog("close"); }
    }

    });
});

</script>

Try this..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM