2011-01-19 82 views
2

我有一個很奇怪的情況,我有以下代碼:ASP.NET定時器導致一個UpdatePanel給出完全回發

<asp:Timer ID="GameClock" runat="server" Interval="5000" Enabled="true" 
    ontick="GameClock_Tick"> 
</asp:Timer> 

<asp:UpdatePanel ID="ItemsUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"> 
     <Triggers> 
      NOTE THE TRIGGER IS COMMENTED OUT 
      <%--<asp:AsyncPostBackTrigger ControlID="GameClock" EventName="Tick" />--%> 
     </Triggers> 
     <ContentTemplate> 
      <asp:ListView ID="PlayerItems" runat="server" GroupItemCount="7" 
              onitemdatabound="PlayerItems_ItemDataBound"> 
              <LayoutTemplate> 
               <table border="1" cellpadding="2" cellspacing="0" runat="server" id="tblProducts"> 
                <tr runat="server" id="groupPlaceholder"> 

                </tr> 
               </table>   
              </LayoutTemplate> 
              <ItemTemplate> 
              <td id="Td1" runat="server" style="vertical-align:top; text-align:left; height:100%;"> 
               <div> 
                <div id="category" runat="server"> 
                 <asp:Panel ID="ItemPanel" runat="server"> 
                 </asp:Panel> 
                </div>   

               </div>  
              </td> 

              </ItemTemplate> 

              <GroupTemplate> 
               <tr runat="server" id="productRow"> 
                <td runat="server" id="itemPlaceholder"></td> 
               </tr>    
              </GroupTemplate> 
             </asp:ListView> 
     </ContentTemplate> 
</asp:UpdatePanel> 

這給出了一個很奇怪的結果:每5秒了我的整個頁面提供了一個完整的回發。當我在(激活)asyncpostbacktrigger中發表評論時,updatepanel不會提供完整的回發。

在PlayerItems_ItemDataBound我有以下代碼(其中,我認爲,並不重要):

protected void PlayerItems_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListViewItemType.DataItem) 
    { 
     ListViewDataItem dataItem = e.Item as ListViewDataItem; 

     if (dataItem != null) 
     { 
      BaseItem myItem = dataItem.DataItem as BaseItem; 
      Panel itemPanel = new Panel(); 
      Literal firstLiteral = new Literal(); 
      firstLiteral.Text += "<div id='smoothmenu1' class='ddsmoothmenu'>"; 
      firstLiteral.Text += "<ul>"; 
      firstLiteral.Text += "<li><img src='Images/Game/Items/" + myItem.ItemImageUrl + "' />"; 

      firstLiteral.Text += "<ul>"; 
      // Add all events bound to item into contextmenu 

      itemPanel.Controls.Add(firstLiteral); 
      foreach (Delegate del in myItem.Actions.Items) 
      { 
       Literal firstItLit = new Literal(); 
       firstItLit.Text += "<li>"; 
       itemPanel.Controls.Add(firstItLit); 

       MethodInfo methodInfo = del.Method; 
       string commandName = myItem.ItemId + "|" + methodInfo.Name; 
       LinkButton btn = new LinkButton(); 
       btn.Text = methodInfo.Name; 
       btn.Click += new EventHandler(btn_Click); 

       btn.CommandName = commandName; 
       itemPanel.Controls.Add(btn); 

       Literal secondItLit = new Literal(); 
       secondItLit.Text += "</li>"; 
       itemPanel.Controls.Add(secondItLit); 
      } 
      Literal btnLiteral = new Literal(); 
      btnLiteral.Text += "</ul>"; 

      btnLiteral.Text += "</li>"; 
      btnLiteral.Text += "</ul>"; 
      btnLiteral.Text += "</div>"; 

      itemPanel.Controls.Add(btnLiteral); 

      Panel panel = (Panel)(e.Item.FindControl("ItemPanel")); 

      panel.Controls.Add(itemPanel); 


     } 

    } 

} 

當我創建一個新的UpdatePanel,ItemsUpdatePanel1,它不會不定時觸發一個完整的回發。 我甚至可以開始將ItemsUpdatePanel中的項目複製到ItemsUpdatePanel1,並突然發生完整的回發。我嘗試了2次單獨的時間,他們開始在不同的時間發生!

任何人都可以請賜我嗎?我只是希望UpdatePanel不會提供完整的回傳,即使沒有計時器。

謝謝!:)

回答

0

本項目是否從ASP.NET 1.1升級?如果是這樣,請檢查您的web.config文件並從中刪除xhtmlConformance標記。我忘記了所有的細節,但是在你的web.config中有這個標籤會導致這種情況發生,並且在.NET 1.1 Web應用程序中默認存在。

+0

不 - 我在.NET 4.0中創建了應用程序..我也只是檢查了web.config,並且標記不存在.. 要壞! – 2011-01-19 22:36:48

相關問題