473,385 Members | 1,856 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,385 software developers and data experts.

Adding Controls (*.ascx) dynamically

I have a registration form that should load different web user controls
based on the selection of a dropdown list. Basically, the user follows the
following steps:

1. user comes to very basic web form, no controls loaded
2. user selects registration type (1 of 4 possible types) from a dropdown
control
3. the dropdown properties are :
autopostback=True OnSelectedIndexChanged="displayUserGroupControl"
4. Now when my displayUserGroupControl fires I would like to load the
control based on their selection.

What is the best way to do this? When the user submits the form I will
create a new "user" record in my database as well as new records in other
tables based on their UserGroup control. Is it fairly easy to get
dynamically loaded controls to talk to each other?

Any tips or best practices would be much appreciated. If I have to, I can
change all the controls to tables in my main form and just hide them based
on the user selection but then the code gets a little hard to read.

Heres what I have right now - I want to confirm that Im doing this the best
way before heading down the wrong road.

Public Sub displayUserGroupControl(ByVal sender As System.Object, ByVal e
As System.EventArgs)

Dim tblName As String
Dim selectValue As String = lbUserType.SelectedItem.Value

Select Case selectValue

Case "1"

phProfilesAndInterests.Controls.Add(LoadControl("c ontrols/register_practitio
ner.ascx"))
Case "2"

phProfilesAndInterests.Controls.Add(LoadControl("c ontrols/register_student.a
scx"))
Case ...

End Select

' Response.Write(selectValue.ToString + "|||<BR>")

End Sub
Nov 18 '05 #1
1 1636
Hello C,

I have an implementation that I discuss on a blog entry: http://www.mattberther.com/2004/10/000559.html

This may work for you...

--
Matt Berther
http://www.mattberther.com
I have a registration form that should load different web user
controls based on the selection of a dropdown list. Basically, the
user follows the following steps:

1. user comes to very basic web form, no controls loaded
2. user selects registration type (1 of 4 possible types) from a
dropdown
control
3. the dropdown properties are :
autopostback=True
OnSelectedIndexChanged="displayUserGroupControl"
4. Now when my displayUserGroupControl fires I would like to load the
control based on their selection.

What is the best way to do this? When the user submits the form I
will create a new "user" record in my database as well as new records
in other tables based on their UserGroup control. Is it fairly easy
to get dynamically loaded controls to talk to each other?

Any tips or best practices would be much appreciated. If I have to, I
can change all the controls to tables in my main form and just hide
them based on the user selection but then the code gets a little hard
to read.

Heres what I have right now - I want to confirm that Im doing this the
best way before heading down the wrong road.

Public Sub displayUserGroupControl(ByVal sender As System.Object,
ByVal e As System.EventArgs)

Dim tblName As String
Dim selectValue As String = lbUserType.SelectedItem.Value
Select Case selectValue

Case "1"

phProfilesAndInterests.Controls.Add(LoadControl("c ontrols/register_pra
ctitio
ner.ascx"))
Case "2"
phProfilesAndInterests.Controls.Add(LoadControl("c ontrols/register_stu
dent.a
scx"))
Case ...
End Select

' Response.Write(selectValue.ToString + "|||<BR>")

End Sub

Nov 18 '05 #2

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

Similar topics

2
by: Big D | last post by:
Hi all, I'm having a problem adding controls to a panel dynamically. I have a usercontrol that I create and try to add 5 times to the panel, but I only ever see the first control. I know it's...
2
by: avivgur | last post by:
Hello, I am writing a program in Visual C# and I have encountered a problem. In my program I want to dynamically create a multitude of controls (thousands) on a form. The problem is that calling...
0
by: Sinisa Ruzin | last post by:
Hi all, I had problem with dynamically adding/removing controls;ascx, Controls.Add(Page.LoadControl... in the same page of the IBuySpy portal. ASP.NET, C#. I added buttons to the main ASCX loaded...
4
by: MattB | last post by:
Hello. I'm creating a page to edit a person's record (name address, etc) using a DataGrid. I want the fields that can be edited to be created at runtime based on a list of columns in web.config....
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
6
by: crazyjh | last post by:
hello i want to add some controls in according of the time. but when the time change, i call the method again to add controls again,No effect! i think maybe i should unload the controls adding...
3
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
2
by: Chris Botha | last post by:
I am adding controls dynamically to the page as per the samples there are on the Web and it works - I can create text boxes, buttons, my own user controls, whatever, on the fly and initialize them...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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
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,...

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.