2017-05-07 42 views
0

我正在研究C#asp.net web窗体项目。它有两个主页面。 I 有一个从数据库读取数据的用户控件, 在html字符串中创建一个无序列表,并用 填充占位符。该用户控件必须自动刷新每2分钟 。我已将此用户控件包含在父级 母版页中。我有以下代码刷新 用户控件,我通过另一个stackoverflow答案获得了该控件。 问题是,整个母版页刷新,我不知道为什么。部分更新不适用于母版页

Is there a way to make that only the user control which has the UpdatePanel 
refreshes? 


    Outer Master Page: 


    <body> 
    <form id="frmMain" role="form" method="post" runat="server"> 
    <div> 
     <uc2:PendingOrders runat="server" ID="PendingOrders" /> 
    </div> 
    <asp:ContentPlaceHolder ID="MainBodyContent" runat="server"> 
    </asp:ContentPlaceHolder> 
    </form> 
</body> 

User Control: 

<asp:ScriptManager ID="myScriptManager" runat="server" 
EnablePartialRendering="True"></asp:ScriptManager> 
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode = "Conditional" 
    runat="server"> 
<ContentTemplate> 

    <asp:Timer ID="Timer1" runat="server" Interval="20000" 
    OnTick="Timer1_Tick"></asp:Timer> 

    <asp:PlaceHolder runat="server" id="lblMyOrders"></asp:PlaceHolder> 

    </ContentTemplate> 
    <Triggers> 
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> 
    </Triggers> 
    </asp:UpdatePanel> 

    User Control Code behind: 

    protected void Timer1_Tick(object sender, EventArgs e) 
    { 
     //This method creates the html string with data as an unordered list 
     and 
     //populates asp:PlaceHolder inte updatepanel 
     GetData(); 
    } 

回答

0

UpdatePanel1的内容将由Timer1_Tick更新。
“整个母版页刷新”意味着母版页的Page_Load会在Timer1被触发时调用?
UpdatePanel始终将整个页面发送回服务器,并只呈现UpdatePanel1的内容。

+0

是的,就是这样发生的事情。首先进入主页面的page_load事件,然后进入Timer1_Tick。因为这个页面闪烁。我想避免它。 – Massey

+0

只UpdatePanel1将闪烁*** [ASP.NET页面生命周期概述](https://msdn.microsoft.com/en-us/library/ms178472.aspx) – Rainmaker

+0

整个页面重新加载并闪烁! – Massey