joe_pool_is
Contributor
I am looking for a smarter method of collecting data from a webform. The form I am currently working on only has 15 different variables to collect from, but a form could forseeably have many more.
Currently, to collect form data, I am stuck writing something like this:
[/color][/color]
Like I said: That works, but a "smarter way" would be something like this:
However, the "smarter way" works too well: It seems to be returning to me the string value of everything on the webpage. Is there a way to tell my code that I only want to collect my data from the input fields?
Also, I would appreciate any suggestions on the best way to handle large collections of data such as this. My "smarter way" is probably not the best way.
Thanks in advance for your help,
Joe[/color][/color]
Currently, to collect form data, I am stuck writing something like this:
Visual Basic:
[font=Courier New][color=black]Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles[/color][/font][font=Courier New][color=black] btnSubmit.Click
[/color][/font][font=Courier New][color=black] Dim strCollection As String
[/color][/font][font=Courier New][color=black] strCollection = txtName.Text
strCollection &= txtAddress.Text
strCollection &= chkHasInternet.Checked.ToString[/color][/font]
[font=Courier New][color=black] ' // etc.
[/color][/font][font=Courier New][color=black]End [/color][/font][color=#0000ff][font=Courier New][color=black]Sub[/color][/font][color=black]
Like I said: That works, but a "smarter way" would be something like this:
Visual Basic:
[font=Courier New][color=black]Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles[/color][/font][font=Courier New][color=black] btnSubmit.Click[/color][/font]
[font=Courier New][color=black] Dim objVariable as Object
[/color][/font][font=Courier New][color=black] Dim strCollection As String[/color][/font]
[font=Courier New][color=black] strCollection = ""
[/color][/font][font=Courier New][color=black] For Each objVariable In Me.Controls[/color][/font]
[font=Courier New] strCollection &= objVariable.ToString & vbCrLf[/font]
[font=Courier New] Next[/font][color=black]
[/color][font=Courier New][color=black]End [/color][/font][color=#0000ff][font=Courier New][color=black]Sub[/color][/font][color=black]
Also, I would appreciate any suggestions on the best way to handle large collections of data such as this. My "smarter way" is probably not the best way.
Thanks in advance for your help,
Joe[/color][/color]