I have a problem whereby the viewstate of a repeater i.e. the controls within the repeater are not maintaing their viewstate.
I have the following:
Repeater 1:
<asp:Repeater ID="rptImages" runat="server">
<ItemTemplate>
<asp:LinkButton Text="Add" CommandName="Add" CommandArgument=<%# Eval("ID") %> runat="server" />
</ItemTemplate>
</asp:Repeater>
When the link button is clicked the value of the CommandArgument is stored in a hidden field on the page.
Upon postback I can't get the value of the hidden field until the prerender event handler has loaded. So in my prerender event I grab the value of the hidden field and store it in a List property, like so:
if (!string.IsNullOrEmpty(this.SelectedImageIDsInput.Text)) {
this.ImageList.Add(this.SelectedImageIDsInput.Text);
}
And the List property looks like so:
public List<string> ImageList {
get {
if (this.ViewState["ImageList"] == null) {
this.ViewState["ImageList"] = new List<string>();
}
return (List<string>)(this.ViewState["ImageList"]);
}
set { this.ViewState["ImageString"] = value; }
}
Once I have stored the value into my List property I bind my second repeater (again within the prerender event):
this.rptSelectedImages.DataSource = this.LightBoxControl.ImageList;
this.rptSelectedImages.DataBind();
The second repeater has a dropdownlist and a textbox within it. The problem is that the viewstate of these child controls is not maintained. I presume it is because with each postback I am rebinding the repeater, therefore it is rebuilt. What I don't know is how I can possibly get round this? The ImageList property is only updated upon a postback, so I obviously have to rebind the repeater with each postback - how else can it be done?
Any help would be greatly appreciated.
Thanks Al