LogoASPAlliance: Articles, reviews, and samples for .NET Developers
Sample Application: XML Form Generator, Part 2: Capturing User Input
by Andrew Mooney
Average Rating: 
Views (Total / Last 10 Days): 23750/ 30

[ Download Code] | [ Run Sample ]
Part 1 of this series demonstrated how to create an XML form using a DataGrid in a web page. The focus of this part is the display of the XML form using XSL to transform it; and then saving the user input to an XML file.

You can actually use one web page to display all of your XML forms. In the Page_Init event, the XML form is loaded, tansformed, and added to the web page. The sample web page, that's included in the download, gets the name of the XML form from the Querystring without the extension (.xml). If there is no form in the Querystring, the sample.xml form is loaded. The XML forms are loaded from the "forms" sub-directory after adding the extension (.xml). The download contains two forms, sample.xml and test.xml.

The XSL file (forms.xsl) transforms the XML form into ASP.NET controls based on the control type. If the control contains list items, then the comma-separated string is split and transformed into ListItems. If the field in the XML form has required setting to "Yes," then a RequiredFieldValidator is added, and if the XML form field "Data" is set to Currency, Date, Double, Integer, or String then a DataTypeCheck CompareValidator is also added.

The Page_Load IsPostBack event will be triggered when the form is submitted. Here the XML form is loaded into a DataSet. The rows of the DataSet are then iterated through to get the form data based on the type of control. A new DataSet is used to hold the form data, which is then saved to the "results" sub-directory named with a GUID and the .xml extension (GUID.xml).

You'll notice that the XML form name is added to the first entry in the results file. This will allow you to save all your results in the same directory and still be able to easily determine the XML form where they originated. Using the GUID for the name is an easy way to prevent overwriting existing result files.

Now, we have a fully working application for building (Part 1) XML forms and using them to capture user input (Part2). The next step is to build a web form for viewing the results. We'll accomplish this in Part 3 of this series.

©Copyright 1998-2019  |  Page Processed at 2019-11-17 10:13:30 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search