473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Iterate through dynamically created form fields

I've written a user control to add form fields to a aspx page:
Private Sub buildFields()
'Label1.Text = "building fields at " & System.DateTime.Now()
Dim themeIDField As New TextBox()
themeIDField.ID = "theme_id"
themeNamePlaceholder.Controls.Add(themeIDField)
End sub

....and call this at page_load. I now need to get the name value pairs
of these fields to submit to a DB procedure. I've tried using
request.form iteration:

For i As Integer = 1 To Request.Form.Count - 1
Label1.Text += Request.Form.Keys(i) + " = " +
Request.Form.Item(i) + "<br/>"
Next

....and this works almost - Request.Form.Keys(i) yields "ctl08$
[field_name here] = [value here]"

Where has ctl08$ come from? Is it related to the placeholder that i
replace when building the field?

<td class="cell_label" style="width: 120px; height: 18px">
Theme Name</td>
<td class="cell_info" style="width: 349px; height: 18px">
<asp:PlaceHolder ID="themeNamePlaceholder"
runat="server"></asp:PlaceHolder>
</td>

Jun 15 '07 #1
3 5821
Hi

Placeholder does not prefix control IDs with its ID as it is not naming container,
but UserControl does. Therefore Ithink that ctrl08 comes from UserControl.

Anyway, it is better to avoid direct Request.Form access and retrieve submitted
values from the controls you have created. You need to populate placeholder
on postback with the same controls.

-yuriy
I've written a user control to add form fields to a aspx page:
Private Sub buildFields()
'Label1.Text = "building fields at " & System.DateTime.Now()
Dim themeIDField As New TextBox()
themeIDField.ID = "theme_id"
themeNamePlaceholder.Controls.Add(themeIDField)
End sub
...and call this at page_load. I now need to get the name value pairs
of these fields to submit to a DB procedure. I've tried using
request.form iteration:

For i As Integer = 1 To Request.Form.Count - 1
Label1.Text += Request.Form.Keys(i) + " = " +
Request.Form.Item(i) + "<br/>"
Next

...and this works almost - Request.Form.Keys(i) yields "ctl08$
[field_name here] = [value here]"

Where has ctl08$ come from? Is it related to the placeholder that i
replace when building the field?

<td class="cell_label" style="width: 120px; height: 18px">
Theme Name</td>
<td class="cell_info" style="width: 349px; height: 18px">
<asp:PlaceHolder ID="themeNamePlaceholder"
runat="server"></asp:PlaceHolder>
</td>

Jun 15 '07 #2
On 15 Jun, 15:31, Yuriy Solodkyy <y.dot.solod...@gmail.comwrote:
Hi

Placeholder does not prefix control IDs with its ID as it is not naming container,
but UserControl does. Therefore Ithink that ctrl08 comes from UserControl.

Anyway, it is better to avoid direct Request.Form access and retrieve submitted
values from the controls you have created. You need to populate placeholder
on postback with the same controls.

-yuriy
I've written a user control to add form fields to a aspx page:
Private Sub buildFields()
'Label1.Text = "building fields at " & System.DateTime.Now()
Dim themeIDField As New TextBox()
themeIDField.ID = "theme_id"
themeNamePlaceholder.Controls.Add(themeIDField)
End sub
...and call this at page_load. I now need to get the name value pairs
of these fields to submit to a DB procedure. I've tried using
request.form iteration:
For i As Integer = 1 To Request.Form.Count - 1
Label1.Text += Request.Form.Keys(i) + " = " +
Request.Form.Item(i) + "<br/>"
Next
...and this works almost - Request.Form.Keys(i) yields "ctl08$
[field_name here] = [value here]"
Where has ctl08$ come from? Is it related to the placeholder that i
replace when building the field?
<td class="cell_label" style="width: 120px; height: 18px">
Theme Name</td>
<td class="cell_info" style="width: 349px; height: 18px">
<asp:PlaceHolder ID="themeNamePlaceholder"
runat="server"></asp:PlaceHolder>
</td>- Hide quoted text -

- Show quoted text -
Hi - thanks for the reply. Could you give me an example of how to
retrieve the values submitted from the form on postback please?

Jun 16 '07 #3
here is sample of user control with dynamic text boxes created on Page_Load.
If possible, you should create controls in Page_Init.

WebUserControl.ascx.vb:
Partial Class WebUserControl
Inherits System.Web.UI.UserControl

Dim DynamicControls(10) As Control
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
For i As Integer = 0 To 9
Dim textBox As New TextBox
textBox.ID = "c_" & i
c_placeHolder.Controls.Add(textBox)
DynamicControls(i) = textBox
Next
End Sub

Protected Sub vb(ByVal sender As Object, ByVal e As System.EventArgs)
Handles c_button.Click
c_label.Text = ""
For i As Integer = 0 To 9
Dim textBox As TextBox = DynamicControls(i)
c_label.Text += String.Format("{0}={1} ", textBox.ID, textBox.Text)
Next
End Sub
End Class

WebUserControl.ascx:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb"
Inherits="WebUserControl" %>
<asp:Label ID="c_label" runat="server" Text="Label"></asp:Label>
<asp:Button ID="c_button" runat="server" Text="Button" />
<br />
<asp:PlaceHolder ID="c_placeHolder" runat="server"></asp:PlaceHolder>

On 15 Jun, 15:31, Yuriy Solodkyy <y.dot.solod...@gmail.comwrote:
>Hi

Placeholder does not prefix control IDs with its ID as it is not
naming container, but UserControl does. Therefore Ithink that ctrl08
comes from UserControl.

Anyway, it is better to avoid direct Request.Form access and retrieve
submitted
values from the controls you have created. You need to populate
placeholder
on postback with the same controls.
-yuriy
>>I've written a user control to add form fields to a aspx page:
Private Sub buildFields()
'Label1.Text = "building fields at " & System.DateTime.Now()
Dim themeIDField As New TextBox()
themeIDField.ID = "theme_id"
themeNamePlaceholder.Controls.Add(themeIDField )
End sub
...and call this at page_load. I now need to get the name value
pairs
of these fields to submit to a DB procedure. I've tried using
request.form iteration:
For i As Integer = 1 To Request.Form.Count - 1
Label1.Text += Request.Form.Keys(i) + " = " +
Request.Form.Item(i) + "<br/>"
Next
...and this works almost - Request.Form.Keys(i) yields "ctl08$
[field_name here] = [value here]"

Where has ctl08$ come from? Is it related to the placeholder that i
replace when building the field?

<td class="cell_label" style="width: 120px; height: 18px">
Theme Name</td>
<td class="cell_info" style="width: 349px; height: 18px">
<asp:PlaceHolder ID="themeNamePlaceholder"
runat="server"></asp:PlaceHolder>
</td>- Hide quoted text -
- Show quoted text -
Hi - thanks for the reply. Could you give me an example of how to
retrieve the values submitted from the form on postback please?

Jun 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lukelrc | last post by:
Hi, I have a dynamically created listbox. I'm trying to get one of the options selected according to a passed value. This is what i have: <select name="txtTheme" id="txtTheme"> ...
14
by: Peter Olcott | last post by:
I want to be able to efficiently build data structures at run-time. These data structures need to be accessed with minimal time. The only a few ways that come immediately to mind would be some...
4
by: EmmettPower | last post by:
Hi, I have a form which includes a field 'number'. When 'number' is changed additional fields ('item_0', etc) are generated on the form using 'onchange'. I want to validate the form using...
3
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns,...
4
by: Stone Chen | last post by:
Hello, I have form that uses javascript createElement to add additional input fields to it. However, my validating script will not process new input fields because it can only find the named...
6
by: Amit Maheshwari | last post by:
I have my aspx page on which i am creating <input type=text> on client side using javascript. Now when i submit my page i need to access these controls to get the value entered by the user. the...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
7
by: Srikanth Ram | last post by:
Hi, I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.