Help getting control name and value of dynamic controls

I have an application which creates a dynamic form consisting of an html table with web controls in the page.  I need a user to be able to fill in this form and then grab the values of each control and save both the control name and the control value to a database.  

This is the Code that I have

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If not ispostback then
Dim infotable As New Table
Dim objparticipant As New Participants.ParticipantInfo
Dim objCustomFields As New CustomFieldController
Dim TypeId As Integer = Types.TypeController.GetTypeId("Participants", "Participant")
infotable = objCustomFields.FillCustomFieldTemplate(TypeId, objparticipant.EntityId, objparticipant.ClientId)
pnlCustomForm.Controls.Add(infotable)
end if
//Public Shared Function FillCustomFieldTemplate(ByVal TypeId As Long, ByVal EntityId As Long, ByVal ClientId As Long) As System.Web.UI.WebControls.Table
Dim objTable As New Table
Dim ProfileId As Integer
Dim ObjCustomFieldTemplates As New CustomFieldController
Dim ObjCustomFieldTemplate As New CustomFieldTemplate
Dim tbl As New System.Web.UI.WebControls.Table
Dim tRow As System.Web.UI.WebControls.TableRow
Dim tCell As System.Web.UI.WebControls.TableCell
Dim tCell2 As System.Web.UI.WebControls.TableCell

For Each ObjCustomFieldTemplate In ObjCustomFieldTemplates.GetCustomFieldTemplates(EntityId, TypeId, ClientId)
tRow = New TableRow
tCell = New TableCell
tCell2 = New TableCell
Dim lbl As New label
If ObjCustomFieldTemplate.LabelText.Trim = "" Then
lbl.Text = "There is a Null Value for this Control"
Else
lbl.Text = ObjCustomFieldTemplate.LabelText
End If
If ObjCustomFieldTemplate.FieldTypeId = 44 Then
Dim textbox As New textbox
textbox.EnableViewState = True
textbox.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
'textbox.ID = CType(Objcustomfieldtemplate.FieldTypeId, String)
'pnlCurProfile.Controls.Add(textbox)
tCell2.Controls.Add(textbox)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 48 Then
Dim mltext As New textbox
mltext.EnableViewState = True
mltext.TextMode = TextBoxMode.MultiLine
mltext.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
'pnlCurProfile.Controls.Add(radio)
tCell2.Controls.Add(mltext)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 47 Then
Dim radio As New RadioButtonList
radio.EnableViewState = True
radio.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
Dim strValues As String = ObjCustomFieldTemplate.FieldValue
Dim sTemp As String() = Split(strValues, ";")
Dim icount As Integer
For icount = 0 To sTemp.GetUpperBound(0) - 1
Dim options As String = sTemp(icount)
radio.Items.Add(options)
Next
'radio.ID = CType(ObjControl.ControlId, String)
'pnlCurProfile.Controls.Add(radio)
tCell2.Controls.Add(radio)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 46 Then
Dim label As New label
label.EnableViewState = True
'label.ID = CType(ObjControl.ControlId, String)
label.Text = ObjCustomFieldTemplate.DefaultValue
label.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
'pnlCurProfile.Controls.Add(label)
tCell2.Controls.Add(label)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 51 Then
Dim hlink As New HyperLink
hlink.EnableViewState = True
'hlink.ID = CType(ObjControl.ControlId, String)
hlink.Text = ObjCustomFieldTemplate.DefaultValue
hlink.NavigateUrl = ObjCustomFieldTemplate.FieldValue
hlink.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
'pnlCurProfile.Controls.Add(hlink)
tCell2.Controls.Add(hlink)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 52 Then
Dim chk As New CheckBoxList
chk.EnableViewState = True
chk.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
Dim strValues As String = ObjCustomFieldTemplate.FieldValue
Dim sTemp As String() = Split(strValues, ";")
Dim icount As Integer
For icount = 0 To sTemp.GetUpperBound(0) - 1
Dim options As String = sTemp(icount)
chk.Items.Add(options)
Next
tCell2.Controls.Add(chk)
ElseIf ObjCustomFieldTemplate.FieldTypeId = 45 Then
Dim ddl As New DropDownList
ddl.EnableViewState = True
ddl.ID = CType(ObjCustomFieldTemplate.TemplateId, String)
Dim strValues As String = ObjCustomFieldTemplate.FieldValue
Dim sTemp As String() = Split(strValues, ";")
Dim icount As Integer
For icount = 0 To sTemp.GetUpperBound(0) - 1
Dim options As String = sTemp(icount)
ddl.Items.Add(options)
Next
tCell2.Controls.Add(ddl)
End If

tCell.Controls.Add(lbl)
tRow.Cells.Add(tCell)
tRow.Cells.Add(tCell2)
objTable.Rows.Add(tRow)

Next
Return objTable
End Function

I realize that some of the above code may not be needed to help, but I just wanted to provide as much as possible. I just need to find a simple way to retrieve the values from these dynamically created feels and save that input.
Any help is greatly appreciated.
Dustin

All Dragons have Dens, but only the DarkDrgn Makes his Den where he pleases...
0
deastman
12/28/2004 5:20:05 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

4 Replies
904 Views

Similar Articles

[PageSpeed] 53

Try this.

1) Recreate the fields on post back. Don't only do it during not postback because you lose all the fields.
2) Write a procedure that
A) loops through all controls in pnlCustomForm like this

For Each ctl In pnlCustomForm .Controls
Dim tbl As HtmlTable = CType(ctl, HtmlTable)
Dim ctltbl As Control
For Each ctltbl In tbl.Controls
Dim row As HtmlTableRow = CType(ctltbl, HtmlTableRow)
Dim ctlrow As Control
For Each ctlrow In row.Controls
Dim cell As HtmlTableCell = CType(ctlrow, HtmlTableCell)
Dim ctlcell As Control
For Each ctlcell In cell.Controls
If ctlcell.GetType Is GetType(TextBox) Then
Dim txt As TextBox = CType(ctlcell, TextBox)

ElseIf ctlcell.GetType Is GetType(DropDownList) Then
Dim ddl As DropDownList = CType(ctlcell, DropDownList)
ElseIf ctlcell.GetType Is GetType(CheckBox) Then
Dim chk As CheckBox = CType(ctlcell, CheckBox)
ElseIf ctlcell.GetType Is GetType(Button) Then
Dim lbl As label = CType(ctlcell, Label)
End If
Next
Next
Next
Next

Of course I am not showing you for all the different types of fields you need. From here you can pull the ID and the Value
Let me know if this helps
0
AWAlger
12/28/2004 6:11:48 PM
This does help immensley Thank You!  However, I do have one question.  When I fully qualified all of the as clauses i.e. changing as controls to as system.web.ui.htmlcontrols etc. when it came to the converting from one type to another VS says that it cannot be converted from one type to another, see below for what I have done:

<code>
For Each ctlrow In row.Controls
Dim cell As System.Web.UI.HtmlControls.HtmlTableCell = CType(ctlrow, System.Web.UI.HtmlControls.HtmlTableCell)
Dim ctlcell As System.Web.UI.HtmlControls.HtmlControl
For Each ctlcell In cell.Controls
If ctlcell.GetType Is GetType(TextBox) Then
Dim txt As TextBox = CType(ctlcell, TextBox)
<code>
This of course is only a small piece of the code obviously,but hopefully it makes sense where I may have made a mistake. Also, I have placed this code in my on click event for a button. Is this proper, and should I just then do somthing such as
(using above as example)
objSave.ID=txt.ID
objsave.Name =txt.name
dataprovider.instance.AddSavedInfo(objSave.ID,objSave.Name)
Dustin

All Dragons have Dens, but only the DarkDrgn Makes his Den where he pleases...
0
deastman
12/28/2004 7:56:53 PM
I did notice that on the example I sent you under Label it says if type is button.

Make sure that all the if statments match the dim statements

//INCORRECT
If ctlcell.GetType Is GetType(Button) Then
Dim lbl As Label = CType(ctlcell, Label)
//CORRECT
If ctlcell.GetType Is GetType(Label) Then
Dim lbl As Label = CType(ctlcell, Label)

as for your other example I am not sure if you can do that but it might be worth the try.
0
AWAlger
12/28/2004 8:25:33 PM
Hey, what's up!  Thanks for the help.  I had already caught that oversite, but thank you for pointing it out.  Also, I am testng everything now, I will let you know how it goes.

Thanks,
D-man
Dustin

All Dragons have Dens, but only the DarkDrgn Makes his Den where he pleases...
0
deastman
12/28/2004 8:34:55 PM
Reply:

Similar Artilces:

web control help, how to get to the method in the control
I have created an upload web control and I am trying to use it on an aspx page. I had a load button in the control however I was asked to remove it from the control and add the button to the aspx page. I created a method in the control that will load the images but I am not sure how to get to this method from the aspx page ? can someone help me to understand what I need to do..  Thank you so much for all the help :)Gina  UserControlInstance.MethodName();...

How get value from a dynamically created control in a user control
HI, I am working with a version of IBuySpy. On one page is a form that contains a user control that lists the items the user purchased, the subtotal, shipping, etc. I wanted to add a DropDownList from which the user could select the shipper. The dropdown list works fine as long as it has .AutoPostBack = false. However, I cannot figure out how to get the value that the user selected when they finally press the submit button on the form. All attempts to locate the control and it's value have failed. I tried drillingdown from the form to the child controls, and sub child controls. N...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Reading form values in dynamically created child controls in a user control
I have a common problem for which I've searched the web for answers for hours to no avail. I have some radiobuttonlists ,dropdownlists,checkboxlists and text controls in a user control. The lists are created statically, however the items in the lists are populated at run time. The lists are displayed in default.aspx (the containing page) and populated on the Page_Load event of the user control .ascx file based on an external data source containing arrays of data. I want to be able to read the values selected by the user from deafult.aspx, the parent page. details: The .ascx...

Dynamically Loading User Control and Maintaining its viewstate. And Getting Values from the control.
 I have a drop down which is populated on the page looad.  When i select an item from drop downlist i get to see two listboxes with add/removing the objects from one left to right listbox and below that i have a user control which should be populated dynamically based on the selectedvalue from drop down list.  So there are three sections that are seen once a selected value is consiedered from drop down list.  Now I am getting the user control using the below code givencase "42": viewRequired = "vw_AncCostSavingsByCarrier_adhoc";    ...

Help with dynamic controls and retrieving data from dynamic controls
I am new to web development. My requirement is Text boxes get generated dynamically based on user input on click of a button called Ok after user enters values to these textboxes when user clicks on submit button ,values user entered to these textboxes have to be retrieved for further calculation I am generating text boxes in the ok button click event how to retrieve value user enters to these n where the procedure for that to be placed here u need to give name to id of every texbox in a specugic patterns so than u can know next time.   static int i = 0;protected...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

Retrieving form element values from dynamic web control
I swear I had this working... But after a week it seemed to stop. I have an aspx file and in it I dynamically load an ascx file that contains a textbox (runat=server). I have a Save button that when clicked saved the value of the textbox in the db e.g: myObj.Save(el.text); where el is the textbox. Now this worked but no more... What seems to happen now is that when I click save, the Page_Load is called before the server_click event of the button, thus loading the value in the textbox first and then picking it up in the click event to save. So it appears that there is no way of actua...

superreview granted: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

superreview requested: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

How to get a changed web form control name to use in javascript?
When you use a user control, all web form controls names get changed by .NET some like ctl0_ctl5_txtFirstName where txtFirstName is the actual name I gave. in Javascript, to refer to this control I can do like document.getElementById('ctl0_ctl5_txtFirstName') but the thing is from time to time, the prefix, in this case ctl0_ctl5_, gets changed again. So the javascript does not work anymore. Is there any way of handling this situation? Is there any server method to get the prefix? If then I can send the prefix to client side and prefix it with actuall control name like var ...

Web resources about - Help getting control name and value of dynamic controls - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

Virginia AG Ends Concealed Reciprocity with 25 States for Lack of Gun Control
Virginia AG Ends Concealed Carry Reciprocity With 25 States For Lack Of Gun Control

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

Kurt Russell Doubles Down: ‘Gun Control Won’t Stop Terrorists’
Kurt Russell Doubles Down: ‘Gun Control Won’t Stop Terrorists’

How Sepp Blatter Lost Control Of His Monster
If Sepp Blatter could take a step back and look at the bigger picture, forgetting for a moment that today’s eight-year ban from all soccer activities ...

GeekWire Deals: Let Siri control your lights with this HomeKit-enabled smart bulbs
... it and opening the right app can be a real pain when you’re used to just flicking a switch. With today’s GeekWire Deals offer, you can control ...

Resources last updated: 12/25/2015 6:09:20 PM