473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic creation of user controls

Hi, I wonder if anyone can tell me how to add user controls to a page
dynamically?

In context: I have a bunch of HTML tables which due to time
constraints can't be populated to a database, so I was planning on
cutting the HTML source and creating a user control from said source.
I will then populate the relevant database for the product with the
name of the user control, so if someone selects product "blah" the
query returns the name of the relevant control with other details.

How then might I add this code to the page, would I better off using
the old style <% -- inline code here -- %> for example
<uc1:<%=some_control_name%> id=" <%=some_control_name%>"
runat="server"> in the aspx web form or by using code-behind?

And would I have register each control that might be used on the page
too?

<%@ Register TagPrefix="uc1" TagName="cb4Way" Src="pecs/cb4Way.ascx"%>
<%@ Register TagPrefix="uc1" TagName="pecs/tubingNTTPec.ascx"

TIA
Nov 18 '05 #1
3 1209

"Adie" <ar*******@h-o-t-m-a-i-l.com> wrote in message
news:fe******************************@news.teranew s.com...
Hi, I wonder if anyone can tell me how to add user controls to a page
dynamically?


There is a LoadControl method that takes a relative path to an ascx as
parameter.

Use a PlaceHolder control where you want your dynamic controls to appear
( say "PlaceHolder1"), then add your control to it:
PlaceHolder1.Controls.Add(LoadControl(relativeASCX Path));
Hans Kesting
Nov 18 '05 #2
Hans Kesting wrote:
"Adie" <ar*******@h-o-t-m-a-i-l.com> wrote in message

Hi, I wonder if anyone can tell me how to add user controls to a page
dynamically?


There is a LoadControl method that takes a relative path to an ascx as
parameter.

Use a PlaceHolder control where you want your dynamic controls to appear
( say "PlaceHolder1"), then add your control to it:
PlaceHolder1.Controls.Add(LoadControl(relativeASC XPath));


Excellent, thank you Hans.
Nov 18 '05 #3
> There is a LoadControl method that takes a relative path to an ascx as
parameter.
In addition, if you want to have some control over the User Control after
loading it, the LoadControl() method returns a reference to the Control you
added. Also, note that when you dynamically add any Control to a WebForm,
you must re-add it with each PostBack in order for it to "remain" on the
page across PostBacks.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:#f**************@TK2MSFTNGP09.phx.gbl...
"Adie" <ar*******@h-o-t-m-a-i-l.com> wrote in message
news:fe******************************@news.teranew s.com...
Hi, I wonder if anyone can tell me how to add user controls to a page
dynamically?


There is a LoadControl method that takes a relative path to an ascx as
parameter.

Use a PlaceHolder control where you want your dynamic controls to appear
( say "PlaceHolder1"), then add your control to it:
PlaceHolder1.Controls.Add(LoadControl(relativeASCX Path));
Hans Kesting

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3491
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
2
16228
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
2
1633
by: Assaf | last post by:
Hi all, My web form creates & displays dynamic controls when a user clicks a button (code below). No problem. But how do I persist a new control? Every postback destroys the object never to be...
3
3634
by: PABruceFan | last post by:
I am dynamically adding rows to an asp:table as a result of a database query. The row consists of a label, a textbox and three checkboxes in that order: LABEL TEXTBOX CHECKBOX1 CHECKBOX3 ...
2
2541
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
3946
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
7
2545
by: msdev | last post by:
Hello, I am creating my own webbrowser to learn VB .Net. I am stuck on an issue with regards to dynamically-created controls, in this case tabs on a tabcontrol and webbrowsers created within...
13
10145
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
2
1931
by: germ | last post by:
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...
0
7193
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,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.