So i am hacking up the control set from the examples for the desktop but am implementing it in a webapp instead.

Seems pretty straight forward, I plop down a label and text field to my page and then set them as controlsets. They get created and no problem. So in code I do this:

[code] Dim controlsToAdd As Integer = 10
mControlsAdded = controlsToAdd

Dim newLabel As QuestionLbl
Dim newField As DataEntry

For r As Integer = 1 To controlsToAdd

// Add new Label below last label
newLabel = New QuestionLbl
newLabel.Text = Str(r) + "."
newLabel.Top = QuestionLbl(r-1).Top + QuestionLbl(r-1).Height + 20
newLabel.Visible = True

// Add new TextField next to TextField
newField = New DataEntry
newField.Top = newLabel.Top
newField.Visible = True


But I end up getting a nilobjectexception on the second pass of my loop at the line:

newLabel.Top = QuestionLbl(r-1).Top + QuestionLbl(r-1).Height + 20

Any ideas of what I am doing wrong here?


You cannot use the “New ControlName” syntax in web apps to add new controls dynamically. Instead, put the control in a Container and add that at runtime using EmbedWithin.

So do I add my 2 controls to a container and then embed multiple containers dynamically? I am not sure I am following you here.


Take a look at these examples:

Sample Applications/Slidersweb

So taking an idea from the examples I have a container and do this in code now:

[code] Dim controlsToAdd As Integer = 10
mControlsAdded = controlsToAdd

Dim test As New TestContainer

Dim r as Integer
Dim top as Integer = 762

For r = 1 to controlsToAdd
test.QuestionLbl.Text = Str® + “.”
test.EmbedWithin(Self, me.OtherSelect.Left, top, test.Width, test.Height)
top = top + 32

So I would think this would add one container after the other which it doesn’t.

What do I need to do to add the same one multiple times like a control set?


You need to create a new Container each time. You are re-using the same container. Put

test = New Container

in the loop.