dynamic user controls in compiled site

G

germ

I am moving a web application from 1.1 to 2.0
This site builds pages dynamically as :
PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx"));
Everything is working fine as long as the web site is updateable - the .ascx
files exist on disk.
I would like to use the non-updateable and single assembly options - no
..ascx files.

I thought that maybe this would work :
PlaceHolder.Controls.Add(LoadControl("AppNameSpace.Controls.Ctl1",null));
This creates the proper object as defined by the code behind class.
However it never creates any child controls - textboxes etc.

Is there an additional step required to instantiate the page controls ?
Is there a class for the .ascx half of the control that I should be loading
instead ?

...

Gerry
 
B

bruce barker

if you pass a string to LoadControl, it wants the path to the file. to
load from the assembly, you need to pass the type and construction
parameters.


PlaceHolder.Controls.Add(
LoadControl(typeof(MyControlClassName),null));

be sure to specify the class name in the page directive.


-- bruce (sqlwork.com)
 
G

germ

thanks bruce

I am using LoadControl(typeof("MyControls.MyCtl"),null);
and this does create the proper control. however no child controls are
never created.
I tried calling CreateChildControls() in the user control OnInit &
OnPrerender methods after which Controls collection is always empty.

by "specify the class name in the page directive" - do you mean in the user
..ascx Control directive ? or in a Register directive on the .aspx ?
The Control directive looks like this : <%@ Control Language="c#"
AutoEventWireup="True" Codebehind="MyCtl.ascx.cs"
Inherits="MyControls.MyCtl"
TargetSchema="http://schemas.microsoft.com/intellisense/nav4-0" %>

using the Register directive on the page defeats the whole purpose of
dynamic control creation.

gerry
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top