This page will walk you through how to build one action page to handle various forms.
WORK IN PROCESS!
Form HTML fields should start with “form_” for this to work.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Collections.Specialized;
protected void Submit_Click(object sender, EventArgs e) { if (Page.IsPostBack) { form.Visible = false; NameValueCollection submittedValuesCollection = Request.Form; Response.Write("<b>Submitted Values:<br /></b>"); Response.Write(Request.Form["start"] + "<br/>"); Response.Write(Request.Form["end"] + "<br/>"); string sInputControl = ""; string sInputValue = ""; string[] sDataElement; string sSQL = ""; foreach (string key in submittedValuesCollection.AllKeys) { sInputControl = string.Format("{0}", key, submittedValuesCollection[key]); sInputValue = string.Format("{1}", key, submittedValuesCollection[key]); try { if (sInputValue != "") { if (sInputControl.Contains("form_")) { sDataElement = sInputControl.Split('_'); Response.Write("<p>Field: " + sDataElement[1]); Response.Write("<br>Value: " + sInputValue); /* sSQL = "INSERT INTO table (category, measure, submitted, start, [end], [count], submittedby) Values ('" + sDataElement[1] + "','" + sDataElement[2] + "','" + DateTime.Now.ToString() + "','" + Request.Form["start"] + "','" + Request.Form["end"] + "','" + sInputValue + "','" + sEmployee + "');"; */ //Response.Write("<br/>SQL: " + sSQL); // sRunSQLStmnt(sSQL); Response.Write("</p>"); } } } catch (Exception ex) { Response.Write("<p>" + ex.ToString() + "</p>"); } } Response.Write("<br /><br />"); } }
Last Updated on October 26, 2015