User Control Property Persistence - How do I get my property value to stay/come back to me?


I have a user control that's rendered in a data bound List View, for example:
<asp:ListView ID="ListBuildings" DataSourceId="ListDataSource" runat="server">
<ItemTemplate>
    <custom:Rater ID="Rater" BuildingId='<%# Eval("BuildingId")%>' runat="server" />
</ItemTemplate>
</asp:ListView>
I set a custom property on my user control called BuildingId, but on post backs I'm not finding the BuildingId property set to what I set it to in the through the list view's databinding.
I can see that on postbacks the listview isn't getting re-binded, it's values are being persisted through viewstate. Why isn't my user control's BuildingId property value being persisted though?
Any input on how I might be able to set a custom property on a user control from within an item template for a data bound control, and then retrieve that value on further postbacks from events in the aformentioned user control would be really appreciated.
Thanks,
bd
-1
brooklynDev
7/16/2008 11:00:48 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 2 Replies
👁️‍🗨️ 2230 Views



In the user control inseta of keeping the value in a varibale keep it in the viewstate and u will find the value after postback
public int BuildingId
{
get{ return convert.ToInt32(viewstate["BuildingId"]);}
set{viewstate["BuildingId"] = value;}
}

Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
1
vik20000in
7/16/2008 11:16:34 AM
thanks
1
brooklynDev
7/16/2008 11:44:40 AM
Reply: