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:
hello

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

--------------
test.aspx

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

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

---------------
test.aspx.vb

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

--------------
App_Code/ApplyBreadCrumbContent.vb

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)

        container.Controls.Add(b)

    End Sub

End Class

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

'contains a repeater control

--------------------------
BreadCrumb.ascx.vb

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>
ASKER CERTIFIED SOLUTION
madhevan_pillai

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