It looks like you are using a composite control. They look a lot like a user control, rather than using an ascx file to create the controls you create them programmatically. The big advantage of this when using a custom control is that you can create an assembly and use it in different projects.
A composite control can inherit either Control or WebControl. Usually, I usually find Control more useful for inheritance, because usually I donโt need a lot of extra things that you get from WebControl, such as style properties, since I usually just style through a single CssClass property.
You also need to make sure your class implements the INamingContainer interface. This ensures that each child control is automatically given a unique name if the control is used multiple times in the same parent container.
The most important thing to do when creating a composite control is to override the Control CreateChildControls method. All the logic for creating controls should go here. The structure will automatically make sure that it is called at the right time in the page life cycle.
Here is a small example:
public class MyCompositeControl : Control, INamingContainer { protected override void CreateChildControls() { Controls.Clear(); var textbox = new TextBox(); textbox.ID = "TextBox1"; Controls.Add(textbox); if (!Page.IsPostBack || !IsTrackingViewState) {
I do not think ASP.NET AJAX should complicate this. The only thing I can think of, you need to make sure that you create the ScriptManager on any page to which the composite control will be added.
Here's a complete example of this on MSDN. Another nice example on this blog .
source share