2009-12-13 107 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

相关问题