views:

2

answers:

0

Can anyone tell me how to fix issue im having with usercontrol inheritence.

  1. create Base usercontrol which contains a label and sets text of it to be "test1" this is set in the designer.

  2. Create a user control which inherits from the base user control.

  3. now try to display the inherited user control on a web page but noting shows. i.e. the controls of the base control are not being created. So how can i make the base controls be rendered. Full Code is below. In the example below i add both the base control and the child control to the page but only one Label displays not 2 which is what i expected. Please can someone help me with this?

--Base USER CONTROL

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControlBase.ascx.cs" Inherits="Product.WebUserControlBase" %>
<asp:Label ID="BaseLabel1" runat="server" Text="test1"></asp:Label>

public partial class WebUserControlBase : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

--Child Control

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="Product.WebUserControl1" %>

public partial class WebUserControl1 : WebUserControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

--Web Page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Product.WebForm1" %>

<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %> <%@ Register src="WebUserControlBase.ascx" tagname="WebUserControlBase" tagprefix="uc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
    <uc2:WebUserControlBase ID="WebUserControlBase1" runat="server" />
    </form>
</body>
</html>