Adding Controls (*.ascx) dynamically

C

C Downey

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("controls/register_practitio
ner.ascx"))
Case "2"

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

End Select

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

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top