Events in dynamic user controls in ASP 2.0

K

Ken Nipper

I am trying to load x number of the exact same user control on the
page. I added the event handling in the user control code. The
problem I have is that the first control loaded works properly but the
next control does not fire its event handler. I know this sounds
confusing but basically its in the form of (question then
dropdownlist/radio buttons with possible answers) multiple times. It's
a troubleshooting tool.

Below is the code in the event handler if it helps:
Protected Sub DropDownList_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles DropDownList.TextChanged
Dim i As Integer = 0
Dim nq As String = String.Empty
nq = nextQuestionArray(Me.DropDownList.SelectedIndex - 1)
Dim DataClass As New DataHandler
Try
Dim index As Integer = 0
While index < DataClass.selectData(nq).Tables(0).Rows.Count
Select Case
CInt(DataClass.selectData(nq).Tables(0).Rows(index).Item(3))
Case 1
Dim newcontrol As DropDownUserControl =
LoadControl("DropDownUserControl.ascx")
newcontrol.question =
DataClass.selectData(nq).Tables(0).Rows(index).Item(0).ToString
newcontrol.secondarytext =
DataClass.selectData(nq).Tables(0).Rows(index).Item(2).ToString
newcontrol.values =
DataClass.selectData(nq).Tables(0).Rows(index).Item(1).ToString.Split(pi
pe)
newcontrol.nextquestion =
DataClass.selectData(nq).Tables(0).Rows(0).Item(4).ToString.Split(pipe)
Me.Parent.FindControl("contentdiv").Controls.Add(newcontrol)
Case 2
Dim newcontrol As RadioButtonsControl =
LoadControl("RadioButtonsUserControl.ascx")
newcontrol.question =
DataClass.selectData(nq).Tables(0).Rows(index).Item(0).ToString
newcontrol.secondarytext =
DataClass.selectData(nq).Tables(0).Rows(index).Item(2).ToString
newcontrol.values =
DataClass.selectData(nq).Tables(0).Rows(index).Item(1).ToString.Split(pi
pe)
Me.Parent.FindControl("contentdiv").Controls.Add(newcontrol)
End Select
index += 1
End While
Catch ex As Exception
'Exception handler snipped out
End Try

Please reply with any suggestions. Thanks in advance.
 

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

Forum statistics

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

Latest Threads

Top