Dynamic WebUserControl in ASP.net 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to load a web user control from code behind. This used to be
something simple in .net 1.1

Dim myControl As ControlName = CType(Page.LoadControl("ControlName .ascx"),
ControlName )

you would then have access to that controls properties, both custom and
inherited. But this doesn't work in asp.net 2.0. You can't use the control
name to access the control dynamically.

Any ideas, or suggestions?
 
Yes, this is a slight problem in how 2.0 does its compilation. In essence
the codebehind for the ASCX is no longer compiled in the same assembly as
the page's codebehind. To make it compile, add this directive to your ASPX:

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

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Back
Top