473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HowTo: Dynamically Add Custom Controls?

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
3 6279
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: macca | last post by:
Hi, I am writing a GUI application. It will have a number of user defined controls( I plan to use/create a user defined control that will output alarm states that the user can also select and...
1
by: Wannabe_Geek | last post by:
Hi Iam new to MS .Net technology just getting along with it....I created a custom control ,which takes in a query and displays the data in a tabular format....something similar to a datagrid. ...
0
by: Earl Teigrob | last post by:
I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist the child controls that are added to my custom...
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
5
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
5
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.