write text field id and vlaues to XML

wxdqz

New Member
Hi, looking fior some help..I have an aspx page, with a form and controls on it so a few text boxes, a few checkboxes and and radio button.I basically want the user to enter some info and when they hit the button the data is written to an XML file, I have to working fine using the XmlTextWriter class.The Elemnets in my XML file are to be the ID value of each of the controls so basically my code is like this when the User hits the button:

protected void btn_Save_Proposal_Click(object sender, EventArgs e) {
// Create a new file in C: dir
XmlTextWriter textWriter = new XmlTextWriter(Server.MapPath("mydata.xml"), null);
// Opens the document
textWriter.WriteStartDocument();

//Use indentation for readability.
textWriter.Formatting = Formatting.Indented;
textWriter.Indentation = 4;
// Write first element
textWriter.WriteStartElement("Autonew");
textWriter.WriteStartElement("auto");
//Title textWriter.WriteStartElement("title");
textWriter.WriteString(rd_title.Text);
textWriter.WriteEndElement();
// End of content
textWriter.WriteEndElement();
textWriter.WriteEndElement();
// Ends the document.
textWriter.WriteEndDocument();
// close writer
textWriter.Close();
}
As u can see this is writing to 2 head elemenets and one child element called 搕itle? this works fine, however I have about 40 text boxes I want to record, all with differing id values, that would mean writing the title code (3 lines) 40 times, what I need is somethig that will loop throght my form (frm_main) and record a tag for each control dynaically, so basiically once a new <asp:textbox> is added to my form, the c# code above will automativally write to the XML file when the submi button is hit?Any ideas?
 
Back
Top