G
Gary Graham
Hello
I have a need to dynamically (programatically) create various different controls (TextBox, RadioButtonList, CheckBox, etc.) at page_load from within a User control - (.ascx). The reason is that the page content is dynamic and we are using a template .ascx page that loads the .ascx page that dynamically populates a panel within itself with the controls and labels
I have no problem at all creating the controls. My problem is retrieving their values on post back.
Using Page.Request("controlID") produces nothing
Is it possible to get the values back? If so, can someone tell me how I can get the control values
Here is some proof of concept sample code from the page_loae event handler in the .ascx control
This control has some tables, literals, and a panel named pnlFormBody on it
If Not IsPostBack The
litHeader.Text = "Dynamic Data Entry Form Example
litTitle.Text = "Please answer the following questions
litInstructions.Text = "This is a block of text that represents an instruction block on a "
& "data entry form.
Dim lit As Litera
Dim tb As TextBo
Dim rbl As RadioButtonLis
Dim cbl As CheckBoxLis
Dim li As ListIte
Dim cb As CheckBo
Dim i As Intege
'begin tabl
lit = New Literal(
lit.Text = "<table>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr><td width=""300"" valign=""top"">Please enter your napnlFormBody</td><td width=""400"">
pnlFormBody.Controls.Add(lit
tb = New TextBox(
tb.ID = "f1_q1_txt1
pnlFormBody.Controls.Add(tb
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" bgcolor=""#eeeeee"" valign=""top""><td>Please select one</td><td>
pnlFormBody.Controls.Add(lit
rbl = New RadioButtonList(
rbl.ID = "f1_q2_rbl1
For i = 1 To
li = New ListItem(
li.Text = "Selection " &
li.Value =
rbl.Items.Add(li
Nex
pnlFormBody.Controls.Add(rbl
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" valign=""top""><td>Please select one or more</td><td>
pnlFormBody.Controls.Add(lit
For i = 1 To
cb = New CheckBox(
cb.ID = "f1_q3_cbx" &
cb.Text = "Choice " &
pnlFormBody.Controls.Add(cb
lit = New Literal(
lit.Text = "<br>
pnlFormBody.Controls.Add(lit
Nex
cb = New CheckBox(
cb.ID = "f1_q3_cbxOther
cb.Text = "Other
pnlFormBody.Controls.Add(cb
lit = New Literal(
lit.Text = "
pnlFormBody.Controls.Add(lit
tb = New TextBox(
tb.ID = "f1_q3_txtOther
pnlFormBody.Controls.Add(tb
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" bgcolor=""#eeeeee"" valign=""top""><td>Will thios work?</td><td>
pnlFormBody.Controls.Add(lit
rbl = New RadioButtonList(
rbl.ID = "f1_q4_yn1
rbl.RepeatDirection = RepeatDirection.Horizonta
li = New ListItem(
li.Text = "Yes
li.Value = "Yes
rbl.Items.Add(li
li = New ListItem(
li.Text = "No
li.Value = "No
rbl.Items.Add(li
pnlFormBody.Controls.Add(rbl
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
' close tabl
lit = New Literal(
lit.Text = "</table>
pnlFormBody.Controls.Add(lit
Els
' attempt to retrieve the dat
Dim i As Intege
Dim q3Ans As Strin
Dim q1Ans As String = Page.Request("f1_q1_txt1"
Dim q2Ans As String = Page.Request("f1_q2_rbl1"
For i = 1 To
If Not Request("f1_q3_cbx" & i) Is Nothing The
q3Ans += "Choice " & i & ",
End I
Nex
If Not Request("f1_q3_cbxOther") Is Nothing The
q3Ans += "Other =
q3Ans += Request("f1_q3_txtOther"
End If
Dim q4Ans As String = Request("f1_q4_yn1")
End If
This control is loaded by the .aspx template page into a panel using the LoadControl method
I get nothing on the Request retrievals when the controls are created in
the user control and it is loaded into the panel on the .aspx page.
However it works just fine if the user control (.ascx) is eliminated and the
controls are loaded directly into the controls collection of the panel on the
..aspx page
Any ideas or help any one???
Thanks,
Gary
I have a need to dynamically (programatically) create various different controls (TextBox, RadioButtonList, CheckBox, etc.) at page_load from within a User control - (.ascx). The reason is that the page content is dynamic and we are using a template .ascx page that loads the .ascx page that dynamically populates a panel within itself with the controls and labels
I have no problem at all creating the controls. My problem is retrieving their values on post back.
Using Page.Request("controlID") produces nothing
Is it possible to get the values back? If so, can someone tell me how I can get the control values
Here is some proof of concept sample code from the page_loae event handler in the .ascx control
This control has some tables, literals, and a panel named pnlFormBody on it
If Not IsPostBack The
litHeader.Text = "Dynamic Data Entry Form Example
litTitle.Text = "Please answer the following questions
litInstructions.Text = "This is a block of text that represents an instruction block on a "
& "data entry form.
Dim lit As Litera
Dim tb As TextBo
Dim rbl As RadioButtonLis
Dim cbl As CheckBoxLis
Dim li As ListIte
Dim cb As CheckBo
Dim i As Intege
'begin tabl
lit = New Literal(
lit.Text = "<table>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr><td width=""300"" valign=""top"">Please enter your napnlFormBody</td><td width=""400"">
pnlFormBody.Controls.Add(lit
tb = New TextBox(
tb.ID = "f1_q1_txt1
pnlFormBody.Controls.Add(tb
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" bgcolor=""#eeeeee"" valign=""top""><td>Please select one</td><td>
pnlFormBody.Controls.Add(lit
rbl = New RadioButtonList(
rbl.ID = "f1_q2_rbl1
For i = 1 To
li = New ListItem(
li.Text = "Selection " &
li.Value =
rbl.Items.Add(li
Nex
pnlFormBody.Controls.Add(rbl
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" valign=""top""><td>Please select one or more</td><td>
pnlFormBody.Controls.Add(lit
For i = 1 To
cb = New CheckBox(
cb.ID = "f1_q3_cbx" &
cb.Text = "Choice " &
pnlFormBody.Controls.Add(cb
lit = New Literal(
lit.Text = "<br>
pnlFormBody.Controls.Add(lit
Nex
cb = New CheckBox(
cb.ID = "f1_q3_cbxOther
cb.Text = "Other
pnlFormBody.Controls.Add(cb
lit = New Literal(
lit.Text = "
pnlFormBody.Controls.Add(lit
tb = New TextBox(
tb.ID = "f1_q3_txtOther
pnlFormBody.Controls.Add(tb
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
'question
lit = New Literal(
lit.Text = "<tr width=""300"" bgcolor=""#eeeeee"" valign=""top""><td>Will thios work?</td><td>
pnlFormBody.Controls.Add(lit
rbl = New RadioButtonList(
rbl.ID = "f1_q4_yn1
rbl.RepeatDirection = RepeatDirection.Horizonta
li = New ListItem(
li.Text = "Yes
li.Value = "Yes
rbl.Items.Add(li
li = New ListItem(
li.Text = "No
li.Value = "No
rbl.Items.Add(li
pnlFormBody.Controls.Add(rbl
lit = New Literal(
lit.Text = "</td></tr>
pnlFormBody.Controls.Add(lit
' close tabl
lit = New Literal(
lit.Text = "</table>
pnlFormBody.Controls.Add(lit
Els
' attempt to retrieve the dat
Dim i As Intege
Dim q3Ans As Strin
Dim q1Ans As String = Page.Request("f1_q1_txt1"
Dim q2Ans As String = Page.Request("f1_q2_rbl1"
For i = 1 To
If Not Request("f1_q3_cbx" & i) Is Nothing The
q3Ans += "Choice " & i & ",
End I
Nex
If Not Request("f1_q3_cbxOther") Is Nothing The
q3Ans += "Other =
q3Ans += Request("f1_q3_txtOther"
End If
Dim q4Ans As String = Request("f1_q4_yn1")
End If
This control is loaded by the .aspx template page into a panel using the LoadControl method
I get nothing on the Request retrievals when the controls are created in
the user control and it is loaded into the panel on the .aspx page.
However it works just fine if the user control (.ascx) is eliminated and the
controls are loaded directly into the controls collection of the panel on the
..aspx page
Any ideas or help any one???
Thanks,
Gary