Limiting the type of child controls a custom control can have

 How does one do this? I'm looking to create a web control that functions similar to the DropDownList control, in that it would only allow certain types of child controls inside of it(ex: DropDownList only allows ListItems in it).

 Am I missing something glaringly obvious about this problem? I can't seem to find any information on how to do it.

12/8/2008 11:58:21 PM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 56

Those aren't child controls.  It is a custom syntax for setting the Property "Items" of the the drop down list.

The inner  contents of a control can either be properites or custom controls.  For instance if you put something inside the tags of a System.Web.UI.Literal control, it is going to set the "Text" property of the Literal control.  If you put something inside of a System.Web.UI.Panel control it is going to treat those as child controls.

When you create a custom control you can specify if the inner contents of the control should be considered properties or childcontrols.  The default is dependant on which base class you inherit from (ie: Control, or CompositeControl, or WebControl)  In all cases you can overide the default.   You do this by decorating your control with some specific attributes.

 Specifically check out the ParseChildrenAttribute, the PersistChildrenAttribute, the DefaultPropertyAttribute.

 You need to decide a couple things for sure.

Do you want the inner contents of your control to specifcy the value of a single property, the values for a collection property (like the drop down list), or to be actuall child controls.

If you really want them to be Child Controls, then thats fine, however you can't easily modify the control to only accept certain child controls and not others.  

If you really want to do that, look into control builders, which are basically a way to fully customize how the page parser looks at your control.

Here is a page to get you started  and and

In fact everything in this section is probably useful to you:

12/9/2008 1:12:09 AM

Similar Artilces:

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET-

Custom web control and child control events
I generate a LinkButtons in a CreateChildControls() method of a custom web control and I want to catch click events of these LinkButtons in this custom web control class (in some method). Is it possible? Martin public class ExampleCompositeControl { public override ControlCollection Controls { get { EnsureChildControls(); return base.Controls; } } protected override void CreateChildControls() { this.Controls.Clear(); myLink = new LinkButton(); myLink.Click += new EventHandler( myLink_Click ); this.Controls.Add( myLink ); ...

Custom Web Control inside another Custom Web Control
Hi I created a custom web control (CusWebNew) that displays some textboxes by adding them to the ControlCollection of the webcontrol. I also created a custom webcontrol (CustWebButton) that inherts from Button control, and overrided the OnClick function. When I use CustWebButton on a regular web form, it seems to function correctly. However, when I added to be part of the ControlCollection of CustWebNew, it stops to work.   Any ideas why? Thanks Hey, What do you mean by stops to work?  Explain what you are trying to do with it and what it doesn't do.Brian"Trust in the...

Web custom control does not maintain values of child controls
Hello everybody A few days now, I am struggling with a custom web control I am creating, which consists of 3 drop down lists (country/city/hotel).Procedure is simple: On country change, I have to fill the cities with autopostback, and on city change I have to fill hotels again with auto postback. I tried many many methods and I am confused... The best I managed to make is keep the state of countries, and render it with the selected country, selected while filling cities with apporpriate data, however I cannot manage to do the same with the cities/hotels since sities does not keep selected va...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Reusing custom web control in the same web control
Hello, I'm newbie in web development and of course I am actually trying to build my first page and I'd like to know if it is possible to make a custom webcontrol that will contain itself. Let's say I want to draw a folder hierarchy in treeview-like structure. I thought I could make a control that will display a folder and if this folder contains subfolders then for each the control will include itself. Is this even possible? What would you suggest me to do to? Thanks in advance. TomTom Hagen If the control can have child controls, then I s...

User Control VB.Net x Web Custom Control
I was thinking in create a user control in VB.Net, and use it in a Asp.Net as possible? So I thought about it is gonna be better than make a Web Custom Control, so i thought again, nope... But i need to know better because a don't have a progress bar in for example.... Could Somebody tell me about??? in a reallity i know the asnwer but i would like to explain by myself... Thank's Antonio...

Is there any web form control that can work as IFRAME html control?????
in html pages, we can use iframe control in which we can load another pages and/or folder explorer. now, i'm developing a web page in which i like to show the folder explorer when user clicks a link. as a prototype, i developed an html page like below: <html> <head><title>Using iFrame to browse a folder</title> </head> <body bgcolor=cyan> <table left=5px top=5px id=tabMain width=90% height=90% border=1 cellspacing=1 cellpadding=1> <tr height=100%> <td width=20% align=center valign=middle> <INPUT TYPE="Butto...

Custom Web Control w/ Child Composite Controls
 I'm trying to create a custom web control with child controls.   I would like to be able to use the child controls stand alone or within the parent control.  Here is the declarative markup: As you can see, the validation fails, though it compiles successfully.  My code (simplified) is below.  Any insight would be appreciated. 1 'Control Builder 2 Public Class FormControlBuilder : Inherits ControlBuilder 3 Public Overrides Function GetChildControlType(ByVal tagName As String, ByVal attributes As IDictionary) As Type 4...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

What is the difference between a Web User Control and a Web Custom Control
Hi ,please could you answer for the following question with example. i know wht they are. but i want to know hw they are existing in web pages with simple example. What is the difference between a Web User Control and a Web Custom Control?  Thanks in AdvanceDilip    Check this out .... hope these might help you out... itsUrDAY  Hi, See the following URLs: to Web User Contr...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

Web resources about - Limiting the type of child controls a custom control can have -

Rate limiting - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

RWW News: Yoho Suggests Limiting Voting Rights To Property Owners - YouTube Right Wing Watch reports on the ...

Government limiting recovery funds 'heartless'
People cut off from their homes or without electricity not eligible in first round of disaster payments.

Wallabies hopeful Nathan Charles says life-limiting disease will never define his achievements
Nathan Charles hates a sob story. Thing is, Nathan Charles has a great story.

Growing Antarctic sea ice limiting access to continent
Australia and other Antarctic neighbour nations are becoming snarled in a looming climate problem affecting operations on the southernmost c ...

Limiting climate change means forgoing vast fuel reserves, Nature study finds
A third of the world's oil reserves, half of gas reserves and 80 per cent of current coal reserves should not be used in the coming decades if ...

EU considers limiting carbon offsets from 2013
EU considers limiting carbon offsets from 2013

Abbott's defence of Credlin a career-limiting move?
Tony Abbott's defence of Peta Credlin against what he says are sexist attacks from his own MPs shows a breathtaking lack of self-reflection. ...

N.W.T. starts limiting flu shots to high-risk groups
Health officials in the N.W.T. are now limiting flu vaccines to those at high-risk, giving priority to women who are pregnant and to children ...

'Maternity tourism': Report recommends limiting citizenship by birth
The federal government should restrict granting citizenship by birth on Canadian soil to children with at least one parent who is a citizen or ...

Resources last updated: 12/5/2015 8:04:48 AM