473,479 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

(Hard one,any expert out threre ? ) Create object from string ? add webcontrols dynamically on page.

Hi there,

I have some webcontrols that i want to add dynamically on a page. I
have stored the path / namespace in database (ex
MyNameSpace.WebControls.Control1) to the class/webcontrol.

Lets say i have a column in database that looks like this.

PageID (int) Webcontrol (varchar)
1 MyNameSpace.WebControls.Control1
1 MyNameSpace.WebControls.Control2

Then i want to add the controls dynamically on the page, anyone know
how to do this ?
I guess i have to create a instance of the webcontrol and the add it
with Controls.add() . But how do i create the instance and add it
dynamically from a string?

Hope anyone can help me with this, some expert out there ?? :)

Thanks
Jesper

Dec 17 '05 #1
4 2146

<je************@yahoo.se> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi there,

I have some webcontrols that i want to add dynamically on a page. I
have stored the path / namespace in database (ex
MyNameSpace.WebControls.Control1) to the class/webcontrol.

Lets say i have a column in database that looks like this.

PageID (int) Webcontrol (varchar)
1 MyNameSpace.WebControls.Control1
1 MyNameSpace.WebControls.Control2

Then i want to add the controls dynamically on the page, anyone know
how to do this ?
I guess i have to create a instance of the webcontrol and the add it
with Controls.add() . But how do i create the instance and add it
dynamically from a string?

Hope anyone can help me with this, some expert out there ?? :)


I am not an expert, just beginning but it you might consider placing
the controls on the webform in design mode with the visible property
set to false, then at runtime simple set the visible property to true as
needed.

Mike

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 17 '05 #2
It's much easier if you have the path. Controls are templated and aren't
instantiated like normal classes.

Control c = Page.LoadControl("~/controls/login.ascx");
container.Controls.Add(c);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

<je************@yahoo.se> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi there,

I have some webcontrols that i want to add dynamically on a page. I
have stored the path / namespace in database (ex
MyNameSpace.WebControls.Control1) to the class/webcontrol.

Lets say i have a column in database that looks like this.

PageID (int) Webcontrol (varchar)
1 MyNameSpace.WebControls.Control1
1 MyNameSpace.WebControls.Control2

Then i want to add the controls dynamically on the page, anyone know
how to do this ?
I guess i have to create a instance of the webcontrol and the add it
with Controls.add() . But how do i create the instance and add it
dynamically from a string?

Hope anyone can help me with this, some expert out there ?? :)

Thanks
Jesper

Dec 17 '05 #3
Assuming that there is some good reason for using a database to dynamically
load controls, I think you've gotten off on the wrong foot. Why are you
storing strings in the database? The names of namespaces and classes is
useful to us humans, but not particularly to computers. It would be more
efficient to store integers in the database. Assuming (again) that you know
what you're storing in the database, you could create Enumerations that
represent different namespaces and classes, and store the enumerated values
in the database. From there it's a simple matter of identifying the Control
to load via its enumerated value.

You would need some sort of mechanism to identify the Controls whose names
are stored in the database anyway. You could do it with Reflection, but that
would be expensive, and I see no benefit gained from it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

<je************@yahoo.se> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi there,

I have some webcontrols that i want to add dynamically on a page. I
have stored the path / namespace in database (ex
MyNameSpace.WebControls.Control1) to the class/webcontrol.

Lets say i have a column in database that looks like this.

PageID (int) Webcontrol (varchar)
1 MyNameSpace.WebControls.Control1
1 MyNameSpace.WebControls.Control2

Then i want to add the controls dynamically on the page, anyone know
how to do this ?
I guess i have to create a instance of the webcontrol and the add it
with Controls.add() . But how do i create the instance and add it
dynamically from a string?

Hope anyone can help me with this, some expert out there ?? :)

Thanks
Jesper

Dec 17 '05 #4
Thanks for all answers!
Kevin i did it your way. Works great thanks !

// Jesper

Dec 17 '05 #5

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

Similar topics

5
4838
by: Jonah Olsson | last post by:
Hello guys, I have an application which is built upon several user controls. That is, I have a default template (default.aspx) that I load a user control into (using placeholders in the...
9
2153
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a...
2
1991
by: Junsan | last post by:
When I am trying to create users through the ASP.NET Configuration in Visual Studio I am getting the following Error (I got the final version of Visual Studio): Exception has been thrown by the...
13
8835
by: Daniel Walzenbach | last post by:
Hi, Imagine the following situation: I have an asp.net application which allows uploading files to a SQL Server 2000 database (Files are stored as type "images"). As a next step I would like to...
8
2453
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
1
1199
by: jesper_lofgren | last post by:
Hi there, I have some webcontrols that i want to add dynamically on a page. I have stored the path / namespace in database (ex MyNameSpace.WebControls.Control1) to the class/webcontrol. ...
2
1846
by: Dabbler | last post by:
I'm getting the following error when I try and insert a row using FormView, ObjectDataSource and stored procedure. The form has 40+ columns on it and I'm not sure how to diagnose where the problem...
3
1472
by: Cas | last post by:
Hi, I want to use a detailsview only for inserting data into a database (for a survey). In order to check the inputted data, i need Templatefield. So I defined a detailsview and a SqlDataSource...
3
3023
by: Administrator | last post by:
Hi, My web development server is a Windows 2000 SP4 system. Had created an aspx page with the following code which I had extracted from 1 of the Microsoft websites: Dim oExcel As Object Dim...
0
6903
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
7027
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,...
0
5318
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,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4468
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
2987
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
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.