简体   繁体   English

回发后UpdatePanel和Repeater呈现页面无响应

[英]UpdatePanel and Repeater render page unresponsive after post-back

I have a page with an UpdatePanel that contains a Repeater and a text box with the number of items in the repeater. 我有一个带有UpdatePanel的页面,其中包含一个Repeater和一个文本框,其中包含Repeater中的项目数。 When I change the value, the page is supposed to post back and redraw the Repeater with the updated number of items. 当我更改该值时,该页面应该回发并使用更新后的项目数重新绘制“ Repeater”。 This works in principle, but the page ends up frozen after post-backs and does not accept any input - in IE 8 only. 从原理上讲,这是可行的,但是页面在回发后最终会冻结,并且不接受任何输入-仅在IE 8中。 It works perfectly fine in Firefox. 它在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. 当我取出UpdatePanel时,页面工作正常,但是当然会在每个回发事件时刷新。 This is not necessarily related to the Repeater on the page. 这不一定与页面上的Repeater有关。 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. 一个更新面板,一个转发器(实际上是2个嵌套的转发器)以及在转发器中引发回发事件的控件。 The server processes the event correctly and returns control, but the browser (IE8) never refreshes the update panel. 服务器正确处理了事件并返回了控制,但是浏览器(IE8)从不刷新更新面板。 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. 发生这种情况时,JIT调试器不会报告任何内容。

I would actually set Triggers within your updatepanel. 我实际上会在您的updatepanel中设置触发器。

I'm not sure you need to call .Update in your code behind as the updatepanel will be updated when the trigger occurs. 我不确定您是否需要在代码中调用.Update,因为在触发发生时updatepanel会被更新。

Try this: 尝试这个:

My gut feeling is that it has something to do with the use of the OnTextChanged event. 我的直觉是它与OnTextChanged事件的使用有关。 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? IE仍然冻结吗?

So I stripped this page down to the minimum and I found out what is doing it - the AjaxToolkit:CalendarExtender. 因此,我将该页面精简到最小,然后我发现它在做什么-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. 要查看问题,请从下拉列表中选择“ 2”,然后在第一个数量字段中输入内容,然后跳出。 The cursor will blink in the next field, but it does not allow input. 光标将在下一个字段中闪烁,但不允许输入。 This happened in IE8, not in Firefox. 这发生在IE8中,而不是Firefox中。

Edit: Actually, when I went back to the full page and removed the CalendarExtender, it was still not working. 编辑:实际上,当我返回整页并删除CalendarExtender时,它仍然无法正常工作。 I do suspect that this issue has to do with controls posting back in the UpdatePanel, but I just can't pin it down. 我确实怀疑此问题与将控件回发到UpdatePanel中有关,但是我无法将其固定下来。 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. 似乎x事物的组合不起作用,而(x-1)事物的任何组合都起作用,这似乎是其中之一。

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>

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

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