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