Search code examples
c#asp.netnestedasp.net-controls

Can you nest asp.net controls?


  1. I want to create control which would contain other controls.

  2. For these other controls I want to create "base" control with some default look and background logic and then derive all other controls from this "base" control.

Is this possible, and how it can be done ?

EDIT: With nesting I mean something like master pages. I would like to have "master control" and within this master control I would like place another controls.


Solution

    1. It is possible. You have to register your control on the one that contains it.

      <%@ Register TagName="Control" TagPrefix="Tag" Src="source/to/your.ascx" %>

      and then use it like:

      <Tag:Control ID="control" runat="server" />

    2. You can inherit code (ascx.cs). All you have to do is to create a base class that inherits from System.Web.UI.UserControl and then inherit from your base class in your control. I don't know about any way of inheriting look (ascx file).