473,382 Members | 1,705 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,382 software developers and data experts.

Pass form to function

I have a web form (Form1) that I would like to pass to a function, iterate
through it, and retrieve the values of the input elements.

I am able to retrieve the element IDs (function below), but keep hitting a
wall trying to get the values.
Public Function send(ByVal TheForm As System.Web.UI.HtmlControls.HtmlForm)

Dim c As Control

For Each c In TheForm.Controls

HttpContext.Current.Response.Write(c.ID)

HttpContext.Current.Response.Write("<br>")

Next

Any help appreciated.

Thanks,

Bob Lehmann
Nov 18 '05 #1
2 1363
You'll have to do something like

Puclic Function GetControlValue (c as Control)
if typeof c is TextBox then return ctype(c,TextBox).Text
else if typeof c is DropDownList then return
ctype(c,DropDownList).SelectedItem
....
....
....
else
throw new ArgumentException("I don't know what to do with " & c.id)
end if
end function
also, a simple for each loop won't get everything done because its a
hierarchical structure, not a simple enumerated list of controls. You'll
hava to build a recursive function for this.

If possible, you might want to do a Page.FindControl(id) for each control
and then retrieve the control's value
"Bob Lehmann" <no****@dontbotherme.zzz> wrote in message
news:OW**************@TK2MSFTNGP10.phx.gbl...
I have a web form (Form1) that I would like to pass to a function, iterate
through it, and retrieve the values of the input elements.

I am able to retrieve the element IDs (function below), but keep hitting a
wall trying to get the values.
Public Function send(ByVal TheForm As System.Web.UI.HtmlControls.HtmlForm)

Dim c As Control

For Each c In TheForm.Controls

HttpContext.Current.Response.Write(c.ID)

HttpContext.Current.Response.Write("<br>")

Next

Any help appreciated.

Thanks,

Bob Lehmann

Nov 18 '05 #2
Excellent! Thanks for your help.

Bob Lehmann

"David Jessee" <dj*****@houston.rr.com> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
You'll have to do something like

Puclic Function GetControlValue (c as Control)
if typeof c is TextBox then return ctype(c,TextBox).Text
else if typeof c is DropDownList then return
ctype(c,DropDownList).SelectedItem
...
...
...
else
throw new ArgumentException("I don't know what to do with " & c.id)
end if
end function
also, a simple for each loop won't get everything done because its a
hierarchical structure, not a simple enumerated list of controls. You'll
hava to build a recursive function for this.

If possible, you might want to do a Page.FindControl(id) for each control
and then retrieve the control's value
"Bob Lehmann" <no****@dontbotherme.zzz> wrote in message
news:OW**************@TK2MSFTNGP10.phx.gbl...
I have a web form (Form1) that I would like to pass to a function, iterate through it, and retrieve the values of the input elements.

I am able to retrieve the element IDs (function below), but keep hitting a wall trying to get the values.
Public Function send(ByVal TheForm As System.Web.UI.HtmlControls.HtmlForm)
Dim c As Control

For Each c In TheForm.Controls

HttpContext.Current.Response.Write(c.ID)

HttpContext.Current.Response.Write("<br>")

Next

Any help appreciated.

Thanks,

Bob Lehmann


Nov 18 '05 #3

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

Similar topics

2
by: Mark | last post by:
Hi - I have a dynamically created table, which has a number of forms - each named consecutively as 'adduserX' where X is a number generated from ASP. Within each form, I need to have a button...
4
by: stanuf | last post by:
Hi! I am new to vb.net and have a question on how to pass a form to a function. Could someone point me to an example or give me a quick example on how to do this. Thank you Stacy
1
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.