Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding Controls (*.ascx) dynamically

Reply
Thread Tools

Adding Controls (*.ascx) dynamically

 
 
C Downey
Guest
Posts: n/a
 
      11-03-2004
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


 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      11-03-2004
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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Controls Dynamically - with Validators Also Added Dynamically Jeffrey Todd ASP .Net 1 06-02-2005 04:33 PM
Adding Controls Dynamically ALPO ASP .Net 1 12-31-2003 07:14 PM
Dynamically adding controls at runtime - event problem Uzi Baruch ASP .Net 0 12-17-2003 10:05 AM
Efficiency of dynamically adding web user controls MC D ASP .Net 4 11-18-2003 07:27 PM
Dynamically adding controls to page SOURCE file John Wallace ASP .Net 0 08-06-2003 08:14 PM



Advertisments