473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=Tr ue OnSelectedIndex Changed="displa yUserGroupContr ol"
4. Now when my displayUserGrou pControl 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 displayUserGrou pControl(ByVal sender As System.Object, ByVal e
As System.EventArg s)

Dim tblName As String
Dim selectValue As String = lbUserType.Sele ctedItem.Value

Select Case selectValue

Case "1"

phProfilesAndIn terests.Control s.Add(LoadContr ol("controls/register_practi tio
ner.ascx"))
Case "2"

phProfilesAndIn terests.Control s.Add(LoadContr ol("controls/register_studen t.a
scx"))
Case ...

End Select

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

End Sub
Nov 18 '05 #1
1 1649
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=Tr ue
OnSelectedIndex Changed="displa yUserGroupContr ol"
4. Now when my displayUserGrou pControl 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 displayUserGrou pControl(ByVal sender As System.Object,
ByVal e As System.EventArg s)

Dim tblName As String
Dim selectValue As String = lbUserType.Sele ctedItem.Value
Select Case selectValue

Case "1"

phProfilesAndIn terests.Control s.Add(LoadContr ol("controls/register_pra
ctitio
ner.ascx"))
Case "2"
phProfilesAndIn terests.Control s.Add(LoadContr ol("controls/register_stu
dent.a
scx"))
Case ...
End Select

' Response.Write( selectValue.ToS tring + "|||<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
42564
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 the first, because a property of the userControl is to display it's name. The code I have is: //Add detatil widgets to the panel ...
2
3710
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 the Controls.Add() method several times or even calling the Controls.AddRange() method once can take a huge amount of time. Therefore, I would like to...
0
1714
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 by desktopdefault.aspx. The buttons were used to "navigate" withing the same page. I had the problem with "fail to load viewstate ...." due to a...
4
3602
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. This is working fine, and I can add a control (TextBox or DropDownList) dynamically for the user to fill in a value. This works well for just adding...
3
2332
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 page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example...
6
1523
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 before,how can i unload it?? pls help me,thanks
3
5472
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 following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
2
359
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 and add them to a placeholder no problem. However when I post back and the page displays again then all of the controls are gone. I create them...
4
4468
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 selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2085
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 we have to send another system
0
926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.