troubleshooting Question

how do i dynamically add a user control

Avatar of miguel_j
miguel_jFlag for Australia asked on
.NET ProgrammingASP.NET
5 Comments1 Solution555 ViewsLast Modified:

this website applies a different masterpage based on the domain.
once the masterpage is applied i want to add different content templates that load different user controls dynamically

error is in my class file

Compilation Error Type 'BreadCrumb' is not defined.

below is my code


<%@ Page Language="vb" EnableViewState="false" AutoEventWireup="false" MasterPageFile="~/MasterPages/Website.Master" CodeBehind="test.aspx.vb" Inherits="Website.test" %>

<%@ Reference Control="~/Controls/BreadCrumb.ascx" %>


Public Partial Class test
    Inherits System.Web.UI.Page

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

        'code to determine domain and apply correct masterpage (irrelevant to the question)
        Dim m As New ApplyMasterPage
        Me.Page.MasterPageFile = m.MasterLocation.ToString()

        MyBase.AddContentTemplate("BreadCrumbContent", New ApplyBreadCrumbContent)

    End Sub

End Class


Public Class ApplyBreadCrumbContent
    Implements System.Web.UI.ITemplate

    Dim b As BreadCrumb 'error here

    Dim p As Page

    Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn

        b = CType(p.LoadControl("~/Controls/BreadCrumb.ascx"), BreadCrumb)


    End Sub

End Class

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="BreadCrumb.ascx.vb" Inherits="Website.BreadCrumb" %>

'contains a repeater control


Public Partial Class BreadCrumb
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'contains data to render the repeater

    End Sub

End Class

MasterPage contains a ContentPlaceHolder
<asp:ContentPlaceHolder ID="BreadCrumbContent" runat="server"></asp:ContentPlaceHolder>

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros