【问题标题】:Why is my asp .net updatePanel timer refreshing the entire page?为什么我的 asp .net updatePanel 计时器刷新整个页面?
【发布时间】:2015-03-29 08:26:24
【问题描述】:

我有一个页面,它根据预加载和加载方法中的一组检查显示特定控件。

我有一个更新面板,其中应在写入文件时显示文件的内容。我通过在更新面板和文本框中有一个计时器来做到这一点。计划是在计时器的每个滴答声中使用文件内容更新文本框。

现在据我所知; https://msdn.microsoft.com/en-us/library/cc295400.aspx 我应该可以只更新更新面板中的文本框而无需刷新整个页面,但我看到我的 page_load 被击中,为什么?

我的代码

            <asp:UpdatePanel ID="updatePnlStatusScreen" runat="server" Visible="False">
                <ContentTemplate>
                    <asp:Timer ID="timerLogFileOutput" runat="server" Enabled="False" Interval="5000" ontick="timerLogOutput_Tick">
                    </asp:Timer>
                    <asp:TextBox ID="tbLogOutputScreen" runat="server" Height="50%" Width="100%">Nothing logged yet...</asp:TextBox>
                </ContentTemplate>
            </asp:UpdatePanel>

【问题讨论】:

    标签: asp.net ajax timer refresh updatepanel


    【解决方案1】:

    更新面板将激活回发和整个页面生命周期(Page_Load 和所有内容),不同之处仅在于呈现 - 更新面板只会导致部分呈现。您应该将不想在回发时运行的代码包装在 if (IsPostBack==false) { .. } 中。

    【讨论】:

      【解决方案2】:

      您需要将 childrenastrigers 设置为 false 和 updatemode=conditional

      <asp:UpdatePanel ID="updatePnlStatusScreen" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional" style="display:none">
                  <ContentTemplate>
                      <asp:Timer ID="timerLogFileOutput" runat="server" Enabled="False" Interval="5000" ontick="timerLogOutput_Tick">
                      </asp:Timer>
                      <asp:TextBox ID="tbLogOutputScreen" runat="server" Height="50%" Width="100%">Nothing logged yet...</asp:TextBox>
                  </ContentTemplate>
              </asp:UpdatePanel>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-31
        • 1970-01-01
        • 1970-01-01
        • 2018-12-11
        • 1970-01-01
        • 2010-09-07
        • 1970-01-01
        相关资源
        最近更新 更多