【问题标题】:updatepanel __dopostback hits .update() but does not refreshupdatepanel __dopostback 命中 .update() 但不刷新
【发布时间】:2009-06-19 00:12:29
【问题描述】:

我有一个包含两个更新面板的页面,每个更新面板都有一个动态生成的网格视图。 Updatepanel1 在计时器上每十秒刷新一次。当在第一个网格中选择一个项目时,第二个更新/网格刷新。

我正在尝试使用 __doPostBack 来完成这项壮举。此方法确实到达服务器并在 updatepanel2 上运行我的 .update。我看到 updatepanel2 获取数据,但表单从未真正更新 updatepanel2。

只有当 updatepanel1 计时器计时并且我将 updatepanel2 模式设置为“始终”时,我才能让 updatepanel2 显示数据。

有人有什么建议吗?

谢谢

【问题讨论】:

    标签: updatepanel


    【解决方案1】:

    好吧,我解决了这个问题。我修改为使用以下方法进行 doPostBack 调用。

    http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      我看到你回答了你自己的问题,但是为了其他人的利益,而不是 doPostBack(),为什么不在 Timer 上设置两者以在指定的时间间隔刷新,或者作为带有“UpdatePanel1.Update”的 Tick 事件方法()" 在方法的末尾?为此,您需要在 Default.aspx 页面代码本身中设置间隔;我选择了 10 毫秒,以便它可以显示一个非常快速的操作的进度:

      <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000" />
      <asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClick="btnDoSomething_Click" />
       <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="conditional"> 
          <ContentTemplate>
              <span id="spnLabel" runat="server">
              <asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick"></asp:Timer> 
          </ContentTemplate>         
          <Triggers >
              <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
          </Triggers>
       </asp:UpdatePanel> 
      

      然后在有更新时调用的代码隐藏中添加 Timer1_Tick 方法 - 在此示例中,从 btnDoSomething_Click() 方法添加到 spnLabel.InnerHtml 的内容:

      protected void btnDoSomething_Click(object sender, EventArgs e)
      {
           Timer1.Enabled = true;
           Timer1.Interval = 10;
           Timer1_Tick(sender, e);
           Timer1.Enabled = false;
      }
      protected void Timer1_Tick(object sender, EventArgs e)
      {
           spnLabel.InnerHtml = "hi";
           UpdatePanel1.Update();
      }
      

      请记住,刷新是由 Timer 间隔控制的,而不是由您调用 Timer1_Tick(sender,e) 时控制的,即使最后有一个 UpdatePanel1.Update() - 例如,如果您将间隔设置为 10000,即使您的操作在此之前多次使用 Timer1_Tick() 方法,它也会在 10 秒后更新。不过,无论如何,最后你仍然需要一个 UpdatePanel1.Update()。

      -汤姆

      【讨论】:

      • 所以我去年换了工作,不再从事这个项目。不过我喜欢你的方法,如果我需要再次做这种事情,我会记住它。我要投票给你,谢谢。
      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2013-02-05
      • 1970-01-01
      相关资源
      最近更新 更多