Merging HTML form with external data

J

Jim Adams

My ASP.Net (VB.Net) app needs to display a filled in form to a web
user from the following:

a) read a form files dynamically from disk (e.g. form1.html)
b) read its corresponding XML file (e.g. form1.xml - basically field
value pairs)

The form data should be merged back into the HTML form so that when
displayed to the user, it looks exactly like it did the moment before
they clicked the form's Submit button.

Any ideas on an approach would be great appreciated.

Thanks,

Jim
 
K

Kevin Spencer

You already described an approach. If you can describe the business
requirements of your app, perhaps we can offer different approaches. Or,
perhaps I misunderstood you. What sort of ideas are you looking for?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
K

Karl

If your form1.html can be a form1.ascx user control, it should be easy. You
could dynamically load the usercontrol in your page.

dim form as Control = Page.LoadControl("form1.ascx")

Then use the control's FindControl method to find your controls

dim usernameTextBox as TextBox = ctype(form.FindControl(XMLs field name),
textbox)
if not usernameTextBox is nothing then
usernameTextBox.Text = XMLs value
end if


You'll probably need to support more than just textboxes, but that can also
easily be done by adding that to your xml file and looping through
everything:

for each node as XmlNode in XmlDocument.SelectSingleNode(XPATH)
dim c as Control = form.FindControl(node.attributes("name").value)
switch case node.attributes("type").value
case "textbox"
ctype(c, textbox).Text = node.attributes("value").value
case "dropdownlist"
ctype(c, DropDownList).selectedIndex
=node.attributes("value").value
end switch
next

Anyways, that's without an editor so it won't work as-is, but will hopefully
give you an idea.

Karl
 
J

Jim Adams

Unfortunately, these will be HTML forms (not .Net) read from disk, so I
cannot take advantage of iterating through the ASPX controls in a page.

Also, reading the forms will be dynamic and there will be additonal
forms added to the system on-the-fly in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top