标签在更新面板内的转发器内部不可见

时间:2009-12-13 21:54:06

标签: asp.net updatepanel repeater

我有一个包含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); 

在页面加载中,我在某些网站上读到的是解决方案,但它没有帮助。

2 个答案:

答案 0 :(得分: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.Call ScriptManager.RegisterPostBackControl()   并传递相关按钮。   这是控件的最佳解决方案   动态添加的,例如   那些在重复模板中。

答案 1 :(得分:0)

第一步是缩小您的问题范围。如果您完全取出UpdatePanel,它可以正常工作吗?

另外,马上就看到pnlPhoto1Comments.Visible设置为false ......?这在我想的某个地方正确设置,否则你甚至不会得到ItemCommand事件。所以可能不是问题。

相关问题