Nested User Control Construction Problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tdyess
    New Member
    • Jul 2008
    • 1

    Nested User Control Construction Problem.

    I'm trying to create a set of nested controls but am having construction problems. Any help would be greatly appreciated. This is a simplified version of my problem. Here is the code:

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup ="true" CodeBehind="Def ault.aspx.cs" Inherits="WebAp plication1._Def ault" %>
    <%@ Register TagPrefix="PWS" TagName="Outer" Src="~/ControlOuter.as cx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <PWS:Outer ID="pwsOuter" runat="server" />
    </body>
    </html>

    ControlOuter.as cx:
    <%@ Control Language="C#" AutoEventWireup ="true" CodeBehind="Con trolOuter.ascx. cs" Inherits="WebAp plication1.Cont rolOuter" %>
    Outer
    <asp:Panel ID="pnlOuterPan el" runat="server" />

    ControlOuter.as cx.cs
    Code:
    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);
            }
        }
    }
    ControlInner.as cx
    <%@ Control Language="C#" AutoEventWireup ="true" CodeBehind="Con trolInner.ascx. cs" Inherits="WebAp plication1.Cont rolInner" %>
    Inner
    <asp:Panel ID="pnlInnerPan el" runat="server" />

    ControlInner.as cx.cs
    Code:
    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); [I]// pnlInnerPanel is null[/I]
            }
        }
    }
Working...