Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 每个页面回发时都会弹出jQuery对话框_C#_Jquery_Asp.net_Updatepanel_Registerstartupscript - Fatal编程技术网

C# 每个页面回发时都会弹出jQuery对话框

C# 每个页面回发时都会弹出jQuery对话框,c#,jquery,asp.net,updatepanel,registerstartupscript,C#,Jquery,Asp.net,Updatepanel,Registerstartupscript,我有一个包含主文件的网页。主文件有一个更新面板,其中包含一个计时器,用于每隔几秒钟显示一次添加/图像。但是,页面的内容占位符不包含在更新面板中。这是母版页的基本标记: <head id="hdMain" runat="server"> <title>Main Master Page</title> <link href="~/Style/custom-theme/jquery-ui-1.10.1.custom.min.css" rel="

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

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

函数OpenDialog(){
$(函数(){
var=false;
var newDialog=$('\
是否要重定向?

\ '); newDialog.dialog({ 身高:250, 宽度:300, 莫代尔:是的, 按钮:{ 是:函数(){ 这是真的; $(此).dialog(“关闭”); }, 否:函数(){ $(此).dialog(“关闭”); } }, 关闭:函数(){ 如果(重定向到某处){ 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);
}

是的,我试过了,但是仍然不起作用。基本上,当我查看源代码时,我看到://
bool isAsyncPostback = ScriptManager.GetCurrent(this).IsInAsyncPostBack;
if (NeedToRunStartupScript() && !isAsyncPostback)
{
    ClientScript.RegisterStartupScript(this.GetType(), "RedirectScript", "Sys.Application.add_load(function() { OpenDialog(); });", true);
}