Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register TagPrefix="PWS" TagName="Outer" Src="~/ControlOuter.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<PWS:Outer ID="pwsOuter" runat="server" />
</body>
</html>
ControlOuter.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ControlOuter.ascx.cs" Inherits="WebApplication1.ControlOuter" %>
Outer
<asp:Panel ID="pnlOuterPanel" runat="server" />
ControlOuter.ascx.cs
Expand|Select|Wrap|Line Numbers
- namespace WebApplication1
- {
- public partial class ControlOuter : System.Web.UI.UserControl
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- ControlInner ci = new ControlInner();
- pnlOuterPanel.Controls.Add(ci);
- }
- }
- }
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ControlInner.ascx.cs" Inherits="WebApplication1.ControlInner" %>
Inner
<asp:Panel ID="pnlInnerPanel" runat="server" />
ControlInner.ascx.cs
Expand|Select|Wrap|Line Numbers
- namespace WebApplication1
- {
- public partial class ControlInner : System.Web.UI.UserControl
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Button b = new Button();
- b.Text = "Inner Button";
- pnlInnerPanel.Controls.Add(b); // pnlInnerPanel is null
- }
- }
- }