UpdatePanel 和 Repeater 渲染页面在回发后无响应

发布于 2024-08-19 17:39:53 字数 1699 浏览 2 评论 0原文

我有一个带有 UpdatePanel 的页面,其中包含一个中继器和一个包含中继器中项目数的文本框。当我更改该值时,页面应该回发并使用更新的项目数重新绘制中继器。原则上这是可行的,但页面在回发后最终会被冻结,并且不接受任何输入 - 仅在 IE 8 中。它在 Firefox 中运行得非常好。例如,当我右键单击控件时,不会出现上下文菜单,并且无法在文本框中输入文本。

当我取出 UpdatePanel 时,页面工作正常,但当然会在每个回发事件上刷新。这和页面上的Repeater没有必然的关系。我想我在其他页面上看到了这个。这里有什么技巧呢?

<asp:UpdatePanel ID="uPanel" runat="server" UpdateMode="Conditional" 
  EnableViewState="true" ChildrenAsTriggers="true">
  <ContentTemplate>
  <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
    <asp:TextBox ID="tbItems" runat="server" AutoPostback="true" 
                      OnTextChanged="textchanged_Items"/>                     
  <asp:Repeater id="rptItems" runat="server" 
           OnItemDataBound="repeaterItem_Databound">
        <...>
      </asp:Repeater>


    protected void textchanged_Items(object sender, EventArgs e) {
        try {
            // this methods rebinds the repeater to a List after changing
            // the number of items in the list
            ReflowItemRepeater();   
            // This is not really necessary, since Databind() appears to
            // cause an update. I tried it anyways.               
            uPanel.Update();
        }
        catch (Exception ex) {
            ShowError(this, "Error displaying the item list.", ex, true);
        }
    }

我最终删除了更新面板。

一个月后,不同的页面,我仍然一次又一次地与这个斗争。情况是一样的。 一个更新面板、一个转发器(实际上是 2 个嵌套转发器)以及转发器中触发回发事件的控件。服务器正确处理事件并返回控制,但浏览器(IE8)永远不会刷新更新面板。该页面没有响应,好像处于某种死锁情况。我可以通过单击触发另一个回发事件的按钮(也在更新面板中)来解锁它。但发生这种情况时,面板中的文本框将无法单击或编辑。 而且,这种情况只是第一次发生。一旦我“释放”了锁或其他任何东西,即使我重复导致它的完全相同的步骤,它也不会在此页面上再次发生。

发生这种情况时,JIT 调试器不会报告任何内容。

I have a page with an UpdatePanel that contains a Repeater and a text box with the number of items in the repeater. When I change the value, the page is supposed to post back and redraw the Repeater with the updated number of items. This works in principle, but the page ends up frozen after post-backs and does not accept any input - in IE 8 only. It works perfectly fine in Firefox. For instance, the context menu does not appear when I right-click in controls, and I cannot enter text in text boxes.

When I take out the UpdatePanel, the page works fine, but of course refreshes on every post-back event. This is not necessarily related to the Repeater on the page. I think I am seeing this on other pages. What's the trick here?

<asp:UpdatePanel ID="uPanel" runat="server" UpdateMode="Conditional" 
  EnableViewState="true" ChildrenAsTriggers="true">
  <ContentTemplate>
  <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
    <asp:TextBox ID="tbItems" runat="server" AutoPostback="true" 
                      OnTextChanged="textchanged_Items"/>                     
  <asp:Repeater id="rptItems" runat="server" 
           OnItemDataBound="repeaterItem_Databound">
        <...>
      </asp:Repeater>


    protected void textchanged_Items(object sender, EventArgs e) {
        try {
            // this methods rebinds the repeater to a List after changing
            // the number of items in the list
            ReflowItemRepeater();   
            // This is not really necessary, since Databind() appears to
            // cause an update. I tried it anyways.               
            uPanel.Update();
        }
        catch (Exception ex) {
            ShowError(this, "Error displaying the item list.", ex, true);
        }
    }

I ended up removing the update panel.

One month later, different page, I am still and again fighting this. The situation is the same.
An update panel, a repeater (actually 2 nested repeaters), and a control in the repeater that fires a postback event. The server processes the event correctly and returns control, but the browser (IE8) never refreshes the update panel. The page is unresponsive, as if in some sort of dead-lock situation. I can unlock it by clicking on a button that fires another postback event (also in the update panel). But the text boxes in the panel are not clickable or editable when this happens.
Also, it happens only the first time. Once I have "freed up" the lock, or whatever it is, it will not happen again on this page, even when I repeat the exact same steps that led to it.

When this happens, the JIT debugger does not report anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

超可爱的懒熊 2024-08-26 17:39:53

我实际上会在您的更新面板中设置触发器。

我不确定您是否需要在后面的代码中调用 .Update ,因为当触发发生时 updatepanel 将被更新。

试试这个:

I would actually set Triggers within your updatepanel.

I'm not sure you need to call .Update in your code behind as the updatepanel will be updated when the trigger occurs.

Try this:

呆° 2024-08-26 17:39:53

我的直觉是这与 OnTextChanged 事件的使用有关。为了获得刺激,请尝试在文本框旁边添加一个按钮,并在单击该按钮时重排转发器。 IE 仍然冻结吗?

My gut feeling is that it has something to do with the use of the OnTextChanged event. For kicks, try adding a button next to the text box, and reflow the repeater when the button is clicked instead. Does IE still freeze?

美胚控场 2024-08-26 17:39:53

因此,我将此页面精简到最少,并找到了它的作用 - AjaxToolkit:CalendarExtender。如果我把它拿出来,一切都会正常。不过,我很想知道是否有解决方法。

这是指向我的测试页面的链接。我会坚持几天。

要查看问题,请从下拉列表中选择“2”,然后在第一个数量字段中输入内容并按 Tab 键退出。光标将在下一个字段中闪烁,但不允许输入。这种情况发生在 IE8 中,而不是 Firefox 中。

编辑:实际上,当我返回完整页面并删除 CalendarExtender 时,它仍然无法工作。我确实怀疑这个问题与 UpdatePanel 中发回的控件有关,但我无法确定它。这似乎是其中之一,其中 x 事物的组合不起作用,而 (x-1) 事物的任何组合都起作用。

So I stripped this page down to the minimum and I found out what is doing it - the AjaxToolkit:CalendarExtender. If I take it out, everything works fine. Still, I would be curious to know if there is a workaround.

Here is a link to my test page. I will keep it up for a few days.

To see the issue, select "2" from the drop-down, then type something into the first quantity field and tab out. The cursor will blink in the next field, but it does not allow input. This happened in IE8, not in Firefox.

Edit: Actually, when I went back to the full page and removed the CalendarExtender, it was still not working. I do suspect that this issue has to do with controls posting back in the UpdatePanel, but I just can't pin it down. It seems seems to be one of these things where a combination of x things does not work, while any combination of (x-1) things does work.

稀香 2024-08-26 17:39:53

关于最初的问题,这是一个工作示例。我不知道这是否有帮助,但只是为了确保......

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server"><title>Ajax Test</title></head>
  <body>
    <form id="form1" runat="server">
<asp:ScriptManager runat="server" />

<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
  <ContentTemplate>
    <asp:Label runat="server" AssociatedControlID="txtTest">
       Enter 'fruit' or 'vegetables':
    </asp:Label>
    <asp:TextBox
      runat="server" ID="txtTest" AutoPostBack="true"
      OnTextChanged="Handler_Test_TextChanged"
    />

    <asp:Repeater runat="server" ID="rptItems">
      <HeaderTemplate><ul></HeaderTemplate>
      <ItemTemplate><li><%# Container.DataItem.ToString() %></li></ItemTemplate>
      <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater>
  </ContentTemplate>
</asp:UpdatePanel>
    </form>
  </body>
</html>

<script runat="server">
  static readonly string[] Fruit = new string[]
    { "Apples", "Oranges", "Bananas", "Pears" };

  static readonly string[] Veg = new string[]
    { "Potatoes", "Carrots", "Tomatoes", "Onion" };

  void Handler_Test_TextChanged(object s, EventArgs e)
  {
    if(txtTest.Text == "fruit")            rptItems.DataSource = Fruit;
    else if(txtTest.Text == "vegetables")  rptItems.DataSource = Veg;
    else                                   return;
    rptItems.DataBind();
  }
</script>

Regarding the initial question, here's a working sample. I don't know if it's anyhow helpful, but just to make sure...

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server"><title>Ajax Test</title></head>
  <body>
    <form id="form1" runat="server">
<asp:ScriptManager runat="server" />

<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
  <ContentTemplate>
    <asp:Label runat="server" AssociatedControlID="txtTest">
       Enter 'fruit' or 'vegetables':
    </asp:Label>
    <asp:TextBox
      runat="server" ID="txtTest" AutoPostBack="true"
      OnTextChanged="Handler_Test_TextChanged"
    />

    <asp:Repeater runat="server" ID="rptItems">
      <HeaderTemplate><ul></HeaderTemplate>
      <ItemTemplate><li><%# Container.DataItem.ToString() %></li></ItemTemplate>
      <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater>
  </ContentTemplate>
</asp:UpdatePanel>
    </form>
  </body>
</html>

<script runat="server">
  static readonly string[] Fruit = new string[]
    { "Apples", "Oranges", "Bananas", "Pears" };

  static readonly string[] Veg = new string[]
    { "Potatoes", "Carrots", "Tomatoes", "Onion" };

  void Handler_Test_TextChanged(object s, EventArgs e)
  {
    if(txtTest.Text == "fruit")            rptItems.DataSource = Fruit;
    else if(txtTest.Text == "vegetables")  rptItems.DataSource = Veg;
    else                                   return;
    rptItems.DataBind();
  }
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文