Alecu
Alecu

Reputation: 2708

Asp .Net update panel not updating

I have 2 pages each with an update panel. It has the same content and the same trigger on both pages.

This is how it looks:

                     <div id="rating">
                    <span class="rateTxt">Rate</span>
                    <telerik:RadRating ID="RadRating1" runat="server" ItemCount="5" SelectionMode="Continuous"
                        Precision="Item" Skin="Default" OnRate="RadRating1_Rate" AutoPostBack="true">
                    </telerik:RadRating>
                 </div>
            </li>
         </ul>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <div id="divAddMessage" runat="server" visible="false">
                        <span class="rateTxt">Do you want to add a comment?</span>
                        <asp:TextBox runat="server" ID="txtComment" TextMode="MultiLine" Rows="3" Width="195">
                        </asp:TextBox>
                        <br />
                        <br />
                        <asp:ImageButton runat="server" ID="lnkAddComment" ImageUrl="~/App_Themes/123reg/Images/submit-rating.png"
                            OnClick="lnkAddComment_Click" OnClientClick="showSuccessMessage();" />
                        <br />
                        <br />
                    </div>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="RadRating1" EventName="Rate" />
                </Triggers>
            </asp:UpdatePanel>

Now when the user rates something with the RadRating the Rate event is triggered which causes a postback.

On the handler for the Rate event I do the following:

    protected void RadRating1_Rate(object sender, EventArgs e)
    {
        divAddMessage.Visible = true;
    }

The same code is exactly on 2 pages. On one page it updates the divAddMessage and it becomes visible but on another page it doesn't become visible. Even if I set it to visible on that page when it postback again the Visible property is still false even after setting it to true in the above handler.

I only set the visibily to false in the aspx file and in the above handler I set it to true.

It turns out that I get an error in the javascript console:

Sys.InvalidOperationException: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_mainContentPlaceHolder_updatePanel'. If it is being updated dynamically then it must be inside another UpdatePanel.

I have another update panel inside a multiview. But because the active view is not the one with the update panel on postback the update panel isn't rendered.

Upvotes: 2

Views: 4114

Answers (2)

John Ferguson
John Ferguson

Reputation: 786

I had a custom control and had set the Visible property to false on declaration in the aspx file and that was overriding the visibility of any child elements within the control itself.

Upvotes: 0

Crab Bucket
Crab Bucket

Reputation: 6277

Check the parent/container elements for divAddMessage. Have they got their Visibility set to false. If so then the child element will always be Visible=false even if you have set it explicitly to true. That's driven me mad in the past.

Just a thought

Upvotes: 3

Related Questions