Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > HowTo: Dynamically Add Custom Controls?

Reply
Thread Tools

HowTo: Dynamically Add Custom Controls?

 
 
David Freeman
Guest
Posts: n/a
 
      11-03-2004
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


 
Reply With Quote
 
 
 
 
David Freeman
Guest
Posts: n/a
 
      11-03-2004
sombody plz help!!

David

"David Freeman" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Robert Koritnik
Guest
Posts: n/a
 
      11-03-2004
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Custom Controls Dynamically rwiegel@gmail.com ASP .Net 0 12-02-2007 07:39 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
how do I add an custom attribute to a listitem inside a dynamically created listbox? Rick Spiewak ASP .Net 3 12-23-2004 09:35 PM
HowTo: Dynamically Add Custom Controls? David Freeman ASP .Net 3 11-03-2004 08:38 PM
Custom Control Add Control Dynamically. =?Utf-8?B?V2FubmFiZV9HZWVr?= ASP .Net 1 06-30-2004 01:51 PM



Advertisments