2012-02-14 73 views
0

我正在写一个ASP.Net Web窗体应用程序有一些慢后端操作,所以我试图使用UpdatePanels异步执行操作。为什么UpdatePanel触发会导致所有其他内容消失?

我希望这些操作一次只能执行一次,并在有人正在执行其中一项操作时通知其他用户。作为一种快速和肮脏的方式,我想在它后面放置一个简单的模板对话框,并在操作发生时禁止访问站点。我在网站的所有页面上共享的母版页中执行此操作。

我卡住了UpdatePanel中的模式,并在其上放置了一个计时器来检查当前状态的全局变量(来自ApplicationState)。如果它执行任务,则显示模式,否则通过设置Visibility = False将其禁用。我只想要更新内容,因此我在ScriptManager中确保EnablePartialRendering =“true”,并在UpdatePanel上设置UpdateModel =“Contitional”。我甚至在Timer的Tick事件中调用.Update()。

听起来很不错。为了测试,我得到了随机打开和关闭的模式。到目前为止,计时器可以工作,而模式显示并隐藏起来就像一个冠军。唯一的问题是,在第二次隐藏模式之后,一切都消失了。

因此,模态被隐藏,主页显示正常。然后计时器触发,显示模式,精美地覆盖主页面。计时器再次触发,模式消失,但其他所有事情也一样!

我查看Chrome中“检查元素”背后的活动html源代码,内容已经消失!

我在这里的东西很明显...

这是我的代码:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="OPTH.DesktopRollout.Website.SiteMaster" %> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
    <head runat="server"> 
     <title></title> 
     <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" /> 
     <asp:ContentPlaceHolder ID="HeadContent" runat="server"> 
     </asp:ContentPlaceHolder>  
    </head> 
    <body> 
     <form runat="server"> 
      <asp:ScriptManager ID="MainSM" runat='server' EnablePartialRendering="True" />   

      <asp:Timer runat="server" ID="CheckTimer" Interval="500" OnTick="CheckTimer_Tick"></asp:Timer> 

      <asp:UpdatePanel runat="server" ID="ModalUp" UpdateMode="Conditional" RenderMode="Block" > 
       <Triggers> 
        <asp:AsyncPostBackTrigger controlid="CheckTimer" eventname="Tick" /> 
       </Triggers> 
      <ContentTemplate>    
       <asp:Panel id="modalPnl" runat="server"> 
        <div class="modalPopup"> 
         <div id="modalContent">Currently performing task: '<asp:Literal runat="server" ID="TaskNameLtr" />'. Please wait till it has completed before continuing.</div>     
        </div> 
        <div class="modalOverlay" />  
       </asp:Panel>       
      </ContentTemplate> 
      </asp:UpdatePanel> 

    //... other content is here... just static html and a ContentPlaceHolder for basepage. 

后端代码:

protected void CheckTimer_Tick(object sender, EventArgs e) 
    { 

     modalPnl.Visible = IsExecutingTask; //Returns a random true or false based on time. 
     TaskNameLtr.Text = DateTime.Now.ToShortDateTimeString(); 
     ModalUp.Update(); 
    } 

Senseis!这只年轻的蚱蜢做错了什么?

我不认为这有什么关系呢,但我的CSS:

.modalOverlay 
    { 
     position: fixed; 
     width: 100%; 
     height: 100%;  
     background-color: black; 
     z-index: 1; 

     filter: alpha(opacity=50); /* internet explorer */ 
     -khtml-opacity: 0.5;  /* khtml, old safari */ 
     -moz-opacity: 0.5;  /* mozilla, netscape */ 
     opacity: 0.5;   /* fx, safari, opera */  
    } 

    .modalPopup 
    { 
     position: fixed; 
     margin-left: -225px;  
     top: 40%; 
     left: 50%; 
     width: 450px; 
     height:100px; 
     background-color: white; 
     border: black solid 3px; 
     z-index: 2; 

     filter: alpha(opacity=100); /* internet explorer */ 
     -khtml-opacity: 1;  /* khtml, old safari */ 
     -moz-opacity: 1;  /* mozilla, netscape */ 
     opacity: 1;   /* fx, safari, opera */ 
    } 

    .modalPopup #modalContent 
    { 
     margin: 15px 30px;  
    } 

任何想法?

更新:我刚刚将所有的AJAX代码从MasterPage移到Default.aspx。现在,在异步回传中,Masterpage中的内容保持不变,但Default.aspx中的内容消失。

+0

我不得不使用会话,因为更新面板清除所有母版页变量 – Toolkit 2015-04-17 09:42:07

回答

0

您应该添加再次控件更新面板里面的页面,否则主网页的加载函数清除控制,因此这些控件的行为不工作了

相关问题