Groups | Blog | Home
all groups > asp.net building controls > november 2004 >

asp.net building controls : HowTo: Dynamically Add Custom Controls?


Robert Koritnik
11/3/2004 4:30:21 PM
Ok. First of all you are not creating custom control but a user control.
User control is NEVER a separate DLL but a part of the application DLL.

User controls consist of ascx and a codebehind. If you just want to make an
instance of the codebehind the codebehind doesn't know what is its ASCX
file. Dynamic loading of USER controls should be run with LoadControl()
method which you provide an ASCX file, which on the other hand has the
information about the codebehind to correctly load the class from the DLL to
handle it's content.

--
RobertK
{ Clever? No just smart. }

[quoted text, click to view]

David Freeman
11/4/2004 12:54:41 AM
Hi There!

I'm having trouble dynamically adding custom controls. My custom controls
does not use code-behind but only <script /> block for programming. So as a
result, I don't need to compile my custom controls to dll for them to work.

But I wonder, if I don't compile to dll, can I still dynamically add that
custom control? If so how? Below is how I've tried (and failed).

At top of the page...
<%@ Register TagPrefix="MyControls" Src="DynamicTest.ascx"
TagName="DynamicTest" %>


In the <script /> block...

Sub Page_Load(Sender As Object, e As EventArgs)

Dim objNew as New DynamicTest '<< Raised Error: BC30002: Type
'DynamicTest' is not defined

Controls.Add(objNew)

End Sub

What I'm doing wrong here? I'm really hitting my head against the wall. Plz,
anyone could help, I really appreciate it!

David

David Freeman
11/4/2004 2:32:15 AM
sombody plz help!!

David

[quoted text, click to view]

AddThis Social Bookmark Button