Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Get Child Controls at design-time

Reply
Thread Tools

Get Child Controls at design-time

 
 
WALDO
Guest
Posts: n/a
 
      10-22-2004
I have a Webcontrol that was supposed to act like a panel control. I
manipulated a TemplatedControlDesigner to make an "Edit mode". I save my
template to the controls collection during design-time. Then I use
GetPersistInnerHtml with ControlPersister to push the controls
collection back to the aspx page. It works very well after edit mode.

My problem is initialization. My control won't pick up the inner tags
from the html in the aspx on the first go-round. Since it didn't pick
them up, it pushes blank back out to the aspx, thus clearing my inner
html. I've been fiddling with ParseChildren and PersistChildren and
overriding my Controls property, setting the PersistenceMode and
DesignerSerializationVisibility attributes all day. I can't quite find
the right combination. This thing gets them perfectly during runtime.

I need to know how to get them at design time. Any Ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
WALDO
Guest
Posts: n/a
 
      10-26-2004
OK I figured it out.

I approached it from a different angle. I said, "Well if
System.Web.UI.WebControls.Table can do it, why am I having a problem?"

I looked at the TableDesigner class and saw that it wasn't doing
anything special, so I took a look at Table itself.

I saw that it used
ParseChildren(True, "Rows"), DefaultProperty("Rows")
and didn't specify PersistChildren.

I tried to do the same substituting "Controls" for "Rows". I got an
error in design-time stating that the "Controls" property could not be
programmatically set at design-time.

So what did the Rows property on Table do? It ultimately is a surrogate
property for the Controls Property. It returns a TableRowsCollection
which inherits from ControlCollection. So basically it is the Controls
Property being worked on by proxy.

A-ha!

OK, so what If I made a surrogate property called Content?
All it did was return the Controls property. Would that work as
expected? The answer is a resounding yes!

[VB.Net]
<ParseChildren(True, "Content"), PersistChildren(False), _
DefaultProperty("Content"), Designer(GetType(MyDesigner))> _
Public Class MyControl
Inherits WebControl

'Collect Controls from innerHtml, hide from UI/code.
<PersistenceMode(PersistenceMode.InnerDefaultPrope rty), _
MergableProperty(False), _
Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Public Readonly Property Content As ControlCollection
Get
Return Me.Controls
End Get
End Property

End Class


One of the weird things about this was setting PersistChildern to false.
Intellisense states 'true to persist the child controls as server
control tags; otherwise, false' which seems contradictory to what I
wanted, but after thinking about it, I guess that worked out OK.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

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
HELP! Child controls of child controls not visible to web app lisa@starways.net ASP .Net Building Controls 0 05-05-2005 09:14 PM
Mixing child properties and child controls - how? Donal McWeeney ASP .Net Web Controls 3 02-14-2005 02:51 AM
Insert child controls into User Controls Aquila Deus ASP .Net 1 01-18-2005 10:07 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
How to force the child controls OnClick event before the parent controls CreateChildControls method? Arulraja ASP .Net 3 10-17-2003 04:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57