简体   繁体   English

部分更新不适用于母版页

[英]Partial update doesn't work with master pages

I am working on a C# asp.net web forms project. 我正在研究C#asp.net网络表单项目。 It has two master pages. 它有两个母版页。 I have an user control which reads data from database, creates an un-ordered list in html string and populates a placeholder with it. 我有一个用户控件,该控件从数据库中读取数据,在html字符串中创建无序列表,并使用它填充占位符。 This user control has to be automatically refreshed every 2 minutes. 此用户控件必须每2分钟自动刷新一次。 I have included this usercontrol on the parent master page. 我已将此用户控件包含在父母版页上。 I have the following code to refresh the user control, which I have obtained through another stackoverflow answer. 我有以下代码来刷新用户控件,该控件是通过另一个stackoverflow答案获得的。 The problem is that the entire master page refreshes, and I am not sure why. 问题是整个母版页都会刷新,我不确定为什么。

Is there a way to make that only the user control which has the UpdatePanel refreshes? 有没有办法使只有具有UpdatePanel的用户控件刷新?

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

UpdatePanel1's Content will be update by Timer1_Tick. UpdatePanel1的内容将由Timer1_Tick更新。
"entire master page refreshes" means master page's Page_Load will be call while Timer1 been trigger? “整个母版页刷新”表示在触发Timer1时将调用母版页的Page_Load吗?
UpdatePanel always post entire page back server and only render UpdatePanel1's Content. UpdatePanel始终将整个页面回发到服务器,并且仅呈现UpdatePanel1的内容。

I had the same problem, but in our project the EnablePartialRendering was set to false on the Master Page, if set to true the whole project breaks. 我遇到了同样的问题,但是在我们的项目中,如果将MasterPart页上的EnablePartialRendering设置为true,则将其设置为false。 To fix the problem, I defined another master page without ScriptManager and added the ScriptManager to the page in which I wanted to use UpdatePanels with the EnablePartialRendering attribute set to True. 为了解决该问题,我定义了另一个没有ScriptManager的母版页,并将ScriptManager添加到我想在其中使用UpdatePanels且EnablePartialRendering属性设置为True的页面上。 This fixed the problem. 这解决了问题。

<asp:ScriptManager ID="myScriptManager" runat="server" EnablePartialRendering="True"></asp:ScriptManager> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM