Groups | Blog | Home
all groups > asp.net webcontrols > june 2008 >

asp.net webcontrols : custom container webcontrol question


Lance Wynn
6/16/2008 10:28:19 AM
Hi all,

I *think* I am trying to build a container control in ASP.net using vb.net.
It is essentially just a visual element that wraps whatever other controls I
have in a nice looking box with a title section, and some other visual
elements.

I went down the path of using a Template, so I now have a control that has a
<ContentTemplate> property that I can put all my whatever into, and it
renders with all the visual elements something like:
<mycontrol title="this is the title">
<ContentTemplate>
html stuff, other controls, etc.. here. No programatic access to
child controls except using "findcontrol"
</ContentTemplate>
</mycontrol>

The problem is that none of the controls contained within the usercontrol
are exposed at design time, so handling button events, etc is a bit
cumbersome.

I am thinking I want to change the control so it works more like a Panel
control where I can put whatever between the start/end tags and it will
render it, but still give programatic access to the child controls at design
time.

<mycontrol title="this is the title">
html stuff, other controls, etc... all child controls are accessible
directly from the code behind w/o findcontrol...
</mycontrol>

I am confused as to where to look for documentation to handle this, and so I
have hit a bit of a block. I am probably just missing something very
simple, but I can't figure out what...

Thanks in advance
Lance

Lance Wynn
6/16/2008 8:26:52 PM
Actually, I found that I can just set the ParseChildControls(false)
attribute to the class, and then I handle the HTML by OverRiding the render
children method in the class, and injecting the HTML there, and get rid of
templates completely. The control doesn't look quite as neat as the
template version, but the usage of it is much nicer for what I am doing.

Thanks for the help.
Lance

--
Support Fairtax Legislation
www.fairtax.org

"A government big enough to give you everything you want, is strong enough
to take everything you have."
-Thomas Jefferson

[quoted text, click to view]

Peter Bucher [MVP]
6/17/2008 3:44:34 AM
Hello Lance

[quoted text, click to view]
Set the TemplateInstanceAttribte to SingleInstance,
so you become Access without .FindControl:
- http://www.nikhilk.net/SingleInstanceTemplates.aspx

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
Peter Bucher [MVP]
6/17/2008 8:56:50 AM
Hello Lance

[quoted text, click to view]
Jep, thats an other way, exactly what the original Microsoft Panel-Control
does.

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Lance Wynn
6/17/2008 1:31:25 PM
Thanks for the affirmation. I was concerned the way I was doing it was
perhaps a bit hacky, but if that's the way the panel works, then I feel a
lot more at ease doing it like this.

Thanks again.
Lance

AddThis Social Bookmark Button