gpt4 book ai didi

c# - 在每个页面回发时弹出 jQuery 对话框

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:19 25 4
gpt4 key购买 nike

我有一个包含主文件的网页。主文件有一个包含计时器的更新面板,用于每隔几秒显示一次添加/图像。但是,页面的内容占位符不包含在更新面板中。这是母版页的基本标记:

<head id="hdMain" runat="server">
<title>Main Master Page</title>
<link href="~/Style/custom-theme/jquery-ui-1.10.1.custom.min.css" rel="stylesheet" />
<asp:ContentPlaceHolder
ID="cpHead"
runat="server">
</asp:ContentPlaceHolder>
</head>
<body style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px" scroll="no">
<form id="frmMain" runat="server">
<asp:ScriptManager
ID="smMain"
runat="server">
</asp:ScriptManager>
<div style="height: 671px; width: 1024px; z-index: 0;">
<asp:ContentPlaceHolder
ID="cpMain"
runat="server">
</asp:ContentPlaceHolder>
</div>
<div style="background-color: #192646; height: 97px; width: 1024px">
<asp:UpdatePanel
ID="upMain"
runat="server"
UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tmrMain" />
</Triggers>
<ContentTemplate>
<asp:Timer
ID="tmrMain"
runat="server"
Interval="10000"
OnTick="RotateImage">
</asp:Timer>
<img
id="imgMain"
runat="server"
height="97"
width="1024"
alt=""
src="" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

现在,当我的页面加载时,我需要在决定是否要启动 jQuery 对话框之前进行一些服务器端处理。我在后面的代码中使用下面的代码来执行此操作:

if (NeedToRunStartupScript())
{
ClientScript.RegisterStartupScript(this.GetType(), "RedirectScript", "Sys.Application.add_load(function() { OpenDialog(); });", true);
}

OpenDialog() 在标记中定义如下,带有标题内容占位符:

<script type="text/javascript" src="../Scripts/JQuery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../Scripts/JQuery/jquery-ui-1.10.1.custom.min.js"></script>
<script type="text/javascript">
function OpenDialog() {
$(function () {
var redirectSomewhere = false;
var newDialog = $('<div title="Dialog">\
<p>Do you wish to redirect?</p>\
</div>');

newDialog.dialog({
height: 250,
width: 300,
modal: true,
buttons: {
Yes: function () {
redirectSomewhere = true;
$(this).dialog("close");
},
No: function () {
$(this).dialog("close");
}
},
close: function () {
if (redirectSomewhere) {
window.location.href = "SomePage.aspx";
}
}
});
});
};

确实是非常标准的东西。这段代码有效。然而,每次计时器点击并更新图像时,对话窗口都会再次出现,所以如果我让它在那里停留几分钟,我将有数十个对话窗口叠加在一起。我基本上只需要注册一次对话框,而不是在每次部分回发时都重新初始化。任何帮助,将不胜感激。

最佳答案

你试过像这样检查异步回发吗

bool isAsyncPostback = ScriptManager.GetCurrent(this).IsInAsyncPostBack;
if (NeedToRunStartupScript() && !isAsyncPostback)
{
ClientScript.RegisterStartupScript(this.GetType(), "RedirectScript", "Sys.Application.add_load(function() { OpenDialog(); });", true);
}

关于c# - 在每个页面回发时弹出 jQuery 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20474044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com