By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,285 Members | 2,232 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,285 IT Pros & Developers. It's quick & easy.

Pass form to function

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.