Pass form to function

  • Thread starter Thread starter Bob Lehmann
  • Start date Start date
B

Bob Lehmann

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
 
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
 
Excellent! Thanks for your help.

Bob Lehmann

David Jessee said:
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
 
Back
Top