Some ASP.NET controls only permit items of certain types, for example:
<uc:MyControl runat="server"....>
<MyTableTemplate>
<MyTableRow .... />
<MyTableRow .... />
<MyTableRow .... />
</MyTableTemplate>
</uc:MyControl>
I’m trying to recreate this in my own custom control, such that you can only put MyTableRow objects into the template and Visual Studio will prevent the designer putting anything else in.
I’ve been looking at the ControlBuilder class but I am not fully certain it does what I want. In addition the examples do not mention the nesting I have above where the array of MyTableRow is within another template field.
Does anyone know how to achieve this?
Edit: The UpdatePanel seems to work this way: If you declare an UpdatePanel like this:
<asp:UpdatePanel>
<Triggers>
</Triggers>
</asp:UpdatePanel>
You cannot put anything in the Triggers section other than the two specific controls listed in intellisense, and you get a design-time error if you try. This is the exact behaviour I wish to mimic.
====
I tried to implement Alex’s suggestion, here is my code:
public partial class MyControl : System.Web.UI.UserControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public ActionButtonCollection ActionButtons
{
get;
set;
}
}
public class ActionButtonCollection : Collection<ActionButton>
{
}
public abstract class ActionButtonBase
{
public string Test { get; set; }
}
public class ActionButton : ActionButtonBase
{
}
However with this code there is no intellisense inside
<uc:MyCustomControl runat="server">
<ActionButtons>
</ActionButtons>
</uc:MyCustomControl >
EDIT: added a link to the example of doing this to google docs.
Firstly, build the website and then you’ll be able use this control with IntelliSense.
Actually,
<Triggers>property ofUpdatePanelis not a template. It is just a collection of objects. You could achieve this by declaring you own class and a class which inheritCollection<YourClass>; then just add the public property ofCollection<YourClass>type to your control and you will be able to archive the “update panel triggers” behaviour.Here is an example:
and finally, your control:
then you could use it on your page:
BTW, you cannot put anything to the
Triggerssection other than types which inherit from theUpdatePanelTriggerclass.