2009-12-13 105 views
0

我有一個包含Repeater的UpdatePanel。在轉發器的ItemTemplate中有一個按鈕和一個標籤。在更新面板內的中繼器內不可見標籤

當按鈕被按下時,它執行一些功能,然後將標籤設置爲可見並禁用該按鈕。

但是沒有任何UI更改正在對網頁進行。

下面是代碼,這在調試器步進經過時似乎很好地工作:

protected void CommentRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) 
{ 
    if (e.CommandName == "report") 
    { 
     (e.Item.FindControl("btnReportComment") as ImageButton).Enabled = false; 
     Label thanksLabel = (Label)e.Item.FindControl("lblReportedComment"); 
     thanksLabel.Visible = true; 
    } 

    pnlCommentsUpdater.Update(); 
} 

以及頁面的代碼(不包括中繼器之外的代碼)

<asp:UpdatePanel UpdateMode="Conditional" ID="pnlCommentsUpdater" runat="server"> 
    <ContentTemplate> 
     <asp:LinkButton ID="lnkPhoto1Comments" runat="server" Text="0 Comments" OnClick="lnkPhoto1Comments_Click" CssClass="dark-gray regular bold"></asp:LinkButton>  
     <asp:Panel ID="pnlPhoto1Comments" runat="server" Visible="False"> 
     <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="CommentRepeater_ItemCommand"> 
      <ItemTemplate> 
       <br /> 
       <hr width="100%" size="1" color="#CCCCCC" /> 
       <table width="534" cellpadding="0" cellspacing="0" border="0"> 
        <tr> 
         <td width="150" align="left" valign="top"> 
          <span class="blue small bold"><%# Eval("PostedBy") %>,</span><br /> 
          <span class="light-gray small bold"><%# Eval("DateCreated", "{0:g}") %></span> 
         </td> 
         <td width="20"></td> 
         <td width="252" align="left" valign="top"> 
          <div STYLE="word-wrap:break-word;width:252px;left:0"> 
           <span class="dark-gray small bold"><%# Eval("CommentText") %></span> 
          </div> 
         </td> 
         <td width="20"></td> 
         <td width="92" valign="bottom"> 
          <asp:ImageButton ID="btnReportComment" runat="server" ImageUrl="../images/inappropriate_off.png" CssClass="domclickroll images/inappropriate_on.png images/inappropriate_on.png" AlternateText="Inappropriate" CommandName="report" CommandArgument='<%#Eval("CommentId") %>' /><br /> 
          <asp:Label ID="lblReportedComment" runat="server" Visible="false" CssClass="Regular bold blue" Text="Thanks. We'll check it out!"></asp:Label> 
         </td> 
        </tr> 
       </table> 
      </ItemTemplate> 
     </asp:Repeater> 

正如我所說的,調試器顯示它工作正常,但它不會在單擊按鈕後在瀏覽器中顯示標籤。

任何人都知道我在做什麼錯了?

錯誤是:「Sys.WebForms.PageRequestManagerParserErrorException:無法解析從服務器收到的消息。此錯誤的常見原因是通過調用Response.Write(),響應過濾器,HttpModules ,或者服務器跟蹤已啓用。「

我打電話來

ScriptManager.GetCurrent(Page).RegisterPostBackControl(Repeater1); 
在頁面加載,這是我在一些網站閱讀

是解決方案,但它並沒有幫助。

回答

1

查看此博客帖子...

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

它包含了一些方法來解決這個。關於你的來電...

ScriptManager.GetCurrent(Page).RegisterPostBackControl(Repeater1); 

......我想你應該把按鈕傳遞給RegisterPostBackControl,而不是中繼器。即通過btnReportComment代替。從上面的參考...

3.調用ScriptManager.RegisterPostBackControl() 並傳入有問題的按鈕。 這是動態添加的控件 的最佳解決方案,例如 那些位於重複模板中的解決方案。

+0

在什麼事件處理程序中,我可以調用RegisterPostBackControl,找到關於它的一點信息。 – 2009-12-17 18:14:52

+0

明白了,謝謝! – 2009-12-18 02:44:30

0

第一步是縮小你的問題。如果你完全取出UpdatePanel,它工作正常嗎?

此外,馬上我看到pnlPhoto1Comments.Visible設置爲false ...?這是設置正確的地方我想,否則你甚至不會得到ItemCommand事件。所以可能不是問題。

+0

是的,面板被設置爲true,如果我拿出UpdatePanel它確實工作正常。 發佈錯誤。 – 2009-12-14 04:15:30

相關問題