|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom Web control questionpage? Here's some context so you can get a better idea of why I am asking this question: I am creating a custom treeview with the following attributes: <code> [ Bindable(false), Category("Initialization"), DefaultValue(""), Description("The type of data to render in this TreeView"), Localizable(true) ] public virtual string ViewableDataType { get { string s = (string)ViewState["ViewableDataType"]; return (s == null) ? String.Empty : s; } set { ViewState["ViewableDataType"] = value; } } [ Bindable(false), Category("Initialization"), DefaultValue(""), Description("Value to set the root node as"), Localizable(true) ] public virtual string RootName { get { string s = (string)ViewState["RootName"]; return (s == null) ? String.Empty : s; } set { ViewState["RootName"] = value; } } </code> You would add my treeview to a page with the following code: <code> <PiYD:PiYDTreeView ID="PiYDTreeView1" ViewableDataType="RegionView" RootName="Root" runat="server" ImageSet="Arrows"> </code> Now I would like to be able to use the values assigned to RootName and ViewableDataType in the constructor of my TreeView. Hence the original question, when is the constructor called, and how can I get that data? I am aware that this might not be possible, (i.e. the attributes are set after the constructor call), but hopefully there is a way. No. According to
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx (see the example control hierarchy source code) the webcontrol's *default* constructor is called followed by the setting of the webcontrol properties. Anyway, since you're persisting property information in viewstate, you can be certain that by the time you get to the Load event of the lifecycle, the properties should contain the information you need both the first time the control is loaded and on each subsequent postback. Hint, override your webcontrol's OnLoad event handler and access your properties safely. CaffieneR***@gmail.com wrote:
> No. According to Thanks a lot!!> http://aspnet.4guysfromrolla.com/articles/092904-1.aspx (see the > example control hierarchy source code) > the webcontrol's *default* constructor is called followed by the > setting of the webcontrol properties. > > Anyway, since you're persisting property information in viewstate, you > can be certain that by the time you get to the Load event of the > lifecycle, the properties should contain the information you need both > the first time the control is loaded and on each subsequent postback. > Hint, override your webcontrol's OnLoad event handler and access your > properties safely. >
How to access control in FormView
Are you sure? for delete in GridView FormView vs create How to get CommandField and ButtonField in the toolbox? Binding TextBox paging control? GridView and DetailsView/FormView in seperate pages FormView sample that includes edit/delete? DataView, DataTable, or DataSet? Disable CommandField for some rows of data |
|||||||||||||||||||||||