By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,977 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

HowTo: Dynamically Add Custom Controls?

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
sombody plz help!!

David

"David Freeman" <no******@mailingspam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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. }

"David Freeman" <no******@mailingspam.com> wrote in message
news:#z**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #3

P: n/a
Hello David,

Instead of Dim objNew As New DynamicTest, try this:

Controls.Add(Page.LoadControl("DynamicTest.ascx"))

--
Matt Berther
http://www.mattberther.com
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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.