User control inside update panel causing full page

2019-02-21 12:46发布

问题:

I have a user control with linkbuttons (used for paging) and a repeater inside an update panel. The paging works correctly, but is causing a full page postback every time I click through to the next page.

The update panel looks like this:

<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:Repeater ID="rptOrganizations" runat="server">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th>Organization</th>
                                <th>State</th>
                                <th>Accredited Since</th>
                            </tr>
                        </thead>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:Literal ID="ltlInstitution" runat="server" />
                        </td>
                        <td>
                            <asp:Literal ID="ltlState" runat="server" />
                        </td>
                        <td>
                            <asp:Literal ID="ltlAccreditedDate" runat="server" />
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>

            <uc2:RepeaterPaging ID="rpPager" runat="server" PageSize="10" OnNextButtonClickEvent="btnNext_Click" OnPreviousButtonClickEvent="btnPrev_Click" />
        </ContentTemplate>  
    </asp:UpdatePanel>

And the contents of the user control look like this:

<asp:LinkButton ID="btnPrev" runat="server" OnClick="btnPrev_Click">Previous</asp:LinkButton> | 
<asp:LinkButton ID="btnNext" runat="server" OnClick="btnNext_Click">Next</asp:LinkButton> 

&nbsp;&nbsp;
<asp:Literal ID="ltlNumResults" runat="server" /> results returned.

So far, I have tried adding an async postback trigger for the user control, which does cause an async postback but does not update the rest of the text in the update panel. In otherwords, the async postback occurs and the next page shows up, but the original text in the repeater is there as well just below it.

I have also confirmed that I have IDS set on my linkbuttons, since that can trigger a full postback inside an update panel.

I have tried changing the update panel mode (Always, Conditional, ChildrenAsTriggers, etc.).

None of it makes a difference - the only thing that actually causes an async postback is to use the trigger, but then the rest of the content in the update panel is not updated, so I get duplicate content. Any ideas?

回答1:

Full postback happens if your UpdatePanel cannot render its contents to a <div> (e.g., when it is situated inside of <tr>). So check you html inside of UpdatePanel, you might find the answer there (also, look for some incorrect xhtml, like incorrectly closed elements).



回答2:

Remove the update mode="Always" Don't put anything over that and it should work.

One more thing are you adding script manager to your page or control not?

Without script manager it will not work.