Brett Allen
Brett Allen

Reputation: 5477

Label not becoming visible inside of repeater inside an updatepanel

I have an UpdatePanel that contains a Repeater. in the ItemTemplate of the repeater there is a button and a label.

When the button gets pressed, it performs some functionality, and then sets the label to visible and disables the button.

However none of the UI changes are being made to the webpage.

Here is the code, which when stepping through in debugger appears to work fine:

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();
}

and the page's code (excluding code outside of the repeater)

<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>

As I said, the debugger shows it to be working fine, however it simply doesn ot show the label in the browser after clicking the button.

Anyone know what I'm doing wrong?

The error is: "Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled."

And I am calling

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

in the page load, which I read in some sites is the solution, but it did not help.

Upvotes: 0

Views: 1791

Answers (2)

Martin Peck
Martin Peck

Reputation: 11544

Check out this blog post...

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

It contains a number of approaches to fixing this. With respect to your call...

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

... I think you're supposed to pass the button to RegisterPostBackControl, and not the repeater. i.e pass it btnReportComment instead. From the reference above...

3.Call ScriptManager.RegisterPostBackControl() and pass in the button in question. This is the best solution for controls that are added dynamically, such as those inside a repeating template.

Upvotes: 1

Bryan
Bryan

Reputation: 8778

First step is to narrow down your problem. If you take out the UpdatePanel altogether, does it work OK?

Also, right off the bat I see that pnlPhoto1Comments.Visible is set to false... ? This is getting set correctly somewhere I suppose, otherwise you wouldn't even get the ItemCommand event. So probably not a problem.

Upvotes: 0

Related Questions