Dynamic WebUserControl in ASP.net 2.0

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

Brock Allen

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

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top