Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > UserControls via LoadControl within a TreeView

Thread Tools

UserControls via LoadControl within a TreeView

Keith Patrick
Posts: n/a
I'm trying to do the old "dynamically create controls via LoadControl don't
fire events" thing, but whereas normally, I could put some code in the
viewstate handlers to put the controls back into the control hierarchy
during initialization, the problem in my case is that my base control is a
TreeView, and a TreeView cannot have controls in its Controls collection
(each node contains a usercontrol). Because of that, while I can create the
controls during LoadViewState just fine, I have no place to put the controls
(such as the Controls collection of a parent) that would result in the
events getting wired in. I'm not aware of a way to manually add the event
handlers (i.e. what does OnInit call that wires in the events), so where
could I store the usercontrols to allow them to get initialized with rest of
the control and thus connected to its event handlers?

Reply With Quote
Keith Patrick
Posts: n/a
I found a solution...head-slappingly simple:

override TreeView.CreateControlCollection() to return a regular
ControlCollection, and the controls can be added, getting hooked into the
event system.

Reply With Quote
Keith Patrick
Posts: n/a
OK, I found a solution after overriding a ton of methods in both the tree
and the node. Basically, I missed one key override:
CreateControlCollection(), which, by replacing with a standard "new
ControlCollection(this)", allows me to deposit my controls there so that
they get hooked into the event system OnInit.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cache two usercontrols which contain either menu or treeview will not work? JX ASP .Net 1 12-10-2007 04:13 AM
Executing and rendering user controls via LoadControl and RenderControl Deane ASP .Net Building Controls 0 09-03-2007 08:47 PM
LoadControl and Multiple IDs in UserControls Error Nestor ASP .Net Web Controls 1 11-12-2005 01:58 AM
Events not firing when loading multiple usercontrols with LoadControl Stijn Vrancken via .NET 247 ASP .Net Building Controls 0 03-26-2005 02:11 PM
Problems with UserControls within a DataGrid Anthony Williams ASP .Net Datagrid Control 3 09-22-2003 09:37 AM