I have a user control named Navigation that has a property that holds navigation groups:
protected List<NavigationGroup> NavigationGroups { get; set; }
I set this property during Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
// Get all navigation items.
NavigationGroups = From.Somewhere.Else.Groups;
}
The value can be accessed during other method calls in the control. However, by the time execution hits the Render method, the NavigationGroups property is empty. What is causing the value to disappear, and how do I make it stick?
Even though this all occurs during one load – not trying to keep it between postbacks – I tried storing the property in ViewState, but that didn’t help either. Still disappears between OnPreRender and Render.
EDIT: Adding information from comments.
It looks like the only field that’s losing value is this one, because it’s set to a list that’s created elsewhere. However, making changes to my local list doesn’t affect the other list, and the other list is still valued when my local list is wiped.
Can’t explain why the issue is occuring, because the two
Lists are provably separate, but using a deep copy works: