I've a custom property on a user control which has multiple state/modes. If this property is set in the parent page: I would like for my control to update automatically. Using the property in the page load does not work because it is not initiated.
I can imagine 3 methods to do this:
- On the property, I could add a code block that would call this.DataBind().
- I could add the code by overriding the virtual method DataBind.
- I could create a public proprietary Update method.
I would like any input into what is the best practice in general. More to the point, I've chosen to override the virtual method DataBind. My pseudo code is as such:
public override void DataBind()
{
if (SpecialMode)
{
.. load from database
}
base.DataBind()
}
I'm interested in the ordering of the base.DataBind(). I've seen it typically placed first but after I load the data from the database: I will need to databind to get the data to display.
Any input into these considerations will be greatly appreciated.
To be clear:
This control is a Poll widget. It will typically search and load the poll to display from the Page_Load event. But, it also has a reports mode which allows the page in which the control is embedded to change the Id of the poll to display. This property will not be initiated in Page_Load. Okay, part of this mess is that I've a property for an object, and I've also a duplicated property for the ViewState but only the Id.