首页 > 解决方案 > 如何在页面加载中弹出对话框

问题描述

我在 aspx 中创建了一个如下所示的对话框:

<div id="IsAccountingOk" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="close">X</a><br />
        <asp:Label ID="lblIsAccountingOkHeader" runat="server" Text="Kassekladde:" Font-Size="Large"></asp:Label><br /><br />
        <asp:Label ID="lblMessage" runat="server" Text="Der skal først vælges regnskabsår!"></asp:Label><br />
        <br />
        <asp:Button ID="btnIsAccountingOK" runat="server" Text="Ok" OnClick="btnIsAccountingOK_Click"/>
    </div>
</div>

并且样式如下图所示:

.modalDialog {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0,0,0,0.8);
    z-index: 99999;
    opacity: 0;
    -webkit-transition: opacity 400ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    transition: opacity 400ms ease-in;
    pointer-events: none;
}
.modalDialog:target {
    opacity: 1;
    pointer-events: auto;
}
.modalDialog > div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
}
.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: -12px;
    text-align: center;
    top: -10px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}
.close:hover {
    background: #00d9ff;
}

我的问题是:如何通过 Page_Load 中的代码弹出此对话框 - 无需用户单击按钮?

也许它可以通过 JavaScript 来完成。

我还在javascript中尝试了以下内容:

$(document).ready(function () {
    $('#IsAccountingOk').show();
});

但是当我使用上述方法时 - DIV 上的所有内容都被阻止 - 这不是意图:-(

有关更多信息,我可以通过如下所示的按钮告诉我它已经开始工作:

<asp:Button ID="btnIsAccountingOk" Text="Der skal først vælges et regnskabsår" runat="server" PostBackUrl="#IsAccountingOk"/><br />

更多信息:我在 sitepage.master 中添加了以下行:

<script type="text/javascript" src="scripts/jquery-3.3.1.js"></script>

它帮助很大。

提前致谢。问候迈克尔

标签: javascriptc#cssasp.netcode-behind

解决方案


页面加载时没有要处理的事件处理程序。

$(document).ready(function() {
   //code here
});

您可以使用 $(document).ready() 它会在 DOM 准备好时运行代码并且它不会等待窗口加载(图像、iframe...)


推荐阅读