Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading User control

Status
Not open for further replies.

slwolf8

Technical User
Apr 23, 2001
82
US
I have a user control "header.ascx" that I would like to load into a place holder on some of my webpages. It will be functioning like a header. Can anyone offer me some guidance on how to do this (VB)? I gather that I will need to do something like the following:

Dim ctlHeader as Proj.Header = new Proj.Header
'not sure what goes on this line

Me.placeholder1.Controls.Add(ctlHeader)

Thanks!
 
Use the Page's LoadControl method to get an instance (instead of new):

Code:
'load it as a contol
Dim loadedControl as Control
loadedControl = Me.LoadControl("~/Header.ascx")

'cast it down to a Header, if necessary
Dim ctlHeader as Proj.Header
ctlHeader = DirectCast(loadedControl, Proj.Header)

'add it to the placeholder
Me.placeholder1.Controls.Add(ctlHeader)

[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top