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)

Advertisements

--
Matt Bertherhttp://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("controls/register_pra
> ctitio
> ner.ascx"))
> Case "2"
> phProfilesAndInterests.Controls.Add(LoadControl("controls/register_stu
> dent.a
> scx"))
> Case ...
> End Select
>
> ' Response.Write(selectValue.ToString + "|||<BR>")
>
> End Sub
>

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!