Date: 03/14/05 (Asp Dot Net) Keywords: asp, java, web Here is my obscure problem. I've got a page where a some checkboxes get added dynamically by javascript like so. [input type="checkbox" name="extra" value="uno" /] UnoI can then retrive them in my aspx.cs code like so: string extras = HttpContext.Current.Request.Form["extras"This works as expected and desired unless the javascript winds up adding checkboxes like: [input type="checkbox" name="extra" value="first item" /]First ItemIn which case we get: string extras = HttpContext.Current.Request.Form["extras"Which is not what is desired. So my question is if there is a way to properly retrieve these values using ASP.NET or do I need to rewrite the javascript code so the name attributes are different and an another hidden control tells me what the names to look for are? Solution is here: public static ICollection FormVars(System.Web.HttpRequest request, string varName) { StreamReader sr = new StreamReader(request.InputStream); string post = sr.ReadToEnd(); sr.Close(); ArrayList values = new ArrayList(); string[] labelValues = post.Split('&'); foreach(string lv in labelValues) { if (lv.StartsWith(varName)) { string val = lv.Substring(varName.Length + 1); // varName= values.Add(System.Web.HttpUtility.UrlDecode(val)); } } return values; } ICollection extras = Utils.FormVars(HttpContext.Current.Request, "extra"); Source: http://www.livejournal.com/community/aspdotnet/28923.html
|