ASP Repeater Control in WebPart - Not Maintaining Viewstate

David Speed asked on October 22, 2014 06:42

Hello,

I have an asp:Repeater control in a custom WebPart that binds to a data source (when it's not a postback), and the resulting output is a list of LinkButton controls. However when I click on one of the LinkButtons, the events will not fire as on a postback the ViewState of the repeater is seemingly lost and there are no items in the repeater, and my webpart comes back blank.

How can I get the Repeater to maintain its state?

<asp:Repeater ID="rptRepeater" runat="server" OnItemDataBound="rptRepeater_ItemDataBound">
    <ItemTemplate>
        <asp:LinkButton ID="lnkLink" runat="server" OnClick="lnkLink_Click" />
    </ItemTemplate>
</asp:Repeater>

Correct Answer

Juraj Ondrus answered on December 6, 2014 11:14

Hi David,

I just found this post - if I remember correctly, we were solving this in a support ticket and we figured out that there was actually a bug in Kentico 8.1, which was already fixed in one of the first hotfixes.

Best regards,
Juraj Ondrus

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on October 22, 2014 15:16

I don't believe this has to do with ViewState at all. You need to set the data source for the repeater on every post back, this is common practice for Kentico, specifically in web parts. Kentico will cache the dataset by default OR you can create your own cached dataset. Remove your logic to check for post back and all should work as expected.

0 votesVote for this answer Mark as a Correct answer

David Speed answered on October 27, 2014 01:07

Hi Brenden,

Thanks for your response, and I agree if you set the data source each time then that part of my custom web part would work correctly, however the link button mentioned above when clicked populates a second repeater which in turn has another link button on it that has an event that needs to fire for the web part to work correctly.

Is there a way for the repeaters to maintain their state as they would in a standard aspx page? Unfortunately it would not be feasible to load all the data each time.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.