Inherited User Controls Not Showing Up

B

Brandon Potter

I am building a large template-based ASP.NET app using inheritance and
loading user controls as the method of loading templates and populating
them. I catch the requests for pages in Global.asax and load the desired
page that inherits the (or an inherited class of) base template class.

I have a top-template level class called TemplateControlBase that inherits
from UserControl, a la:
----------------------------------------------
Public Class TemplateControlBase
Inherits System.Web.UI.UserControl

Private strTitle as String = "Untitled"
Public Property Title() As String
Get
Return strTitle
End Get
Set(ByVal Value As String)
strTitle = Value
End Set
End Property

End Class
----------------------------------------------

Now, for a set of pages for the web site, I am trying to create a "toolbar"
of type MyToolbar (which, right now, contains one LiteralControl that says
"I am the toolbar.") that always gets put on top of the Content placeholder
in the template.

So, I have another class...
----------------------------------------------
Public Class MyTemplateWithToolbar
Inherits TemplateControlBase

Public Sub New()
Me.Controls.AddAt(0, New MyToolbar)
End Sub

End Class
----------------------------------------------

I create my user control page (MyTestUserControl.ascx) that inherits from
MyTemplateWithToolbar.

What I don't understand is why the MyToolbar user control never gets placed
on the page. I can replace the Me.Controls.AddAt(0, New MyToolbar) line and
change MyToolbar to LiteralControl("Test text") and the Literal gets added
fine.

And, if I put some debug text in the same Subroutine as the AddAt() method I
can see that it successfully added a MyToolbar object to the Controls
collection.

Is there some other place in the firing order that I'm supposed to add this?
I've tried New(), Init(), and PreRender()... What am I missing?

Thanks,
Brandon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top