/// <summary> /// Adds a new control to the collection. If there is a control with /// the same name, it will be kept intact. /// </summary> /// <param name="name">The name of a control to be added.</param> public void Add (string name) { BaseControl bc = this[name]; if (bc != null) return; bc = new BaseControl (); bc.Name = name; base.BaseAdd (name, bc); }
private void ExtractFormAndHiddenControls (Response response, string formId) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument (); htmlDoc.LoadHtml (response.Body); StringBuilder tempxml = new StringBuilder (); StringWriter tsw = new StringWriter (tempxml); htmlDoc.OptionOutputAsXml = true; htmlDoc.Save (tsw); XmlDocument doc = new XmlDocument (); doc.LoadXml (tempxml.ToString ()); const string HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable); nsmgr.AddNamespace ("html", HTML_NAMESPACE); #if USE_CORRECT_FORMID XmlNode formNode = doc.SelectSingleNode ("//html:form[@name='" + formId + "']", nsmgr); #else XmlNode formNode = doc.SelectSingleNode ("//html:form", nsmgr); #endif if (formNode == null) throw new ArgumentException ("Form with id='" + formId + "' was not found in document: " + response.Body); string actionUrl = formNode.Attributes["action"].Value; if (actionUrl != null && actionUrl != string.Empty) base.Url = actionUrl; XmlNode method = formNode.Attributes["method"]; if (method != null && "POST" == method.Value.ToUpper(CultureInfo.InvariantCulture)) base.IsPost = true; else base.IsPost = false; #if USE_CORRECT_FORMID foreach (XmlNode inputNode in formNode.SelectNodes ("//html:input", nsmgr)) #else foreach (XmlNode inputNode in doc.SelectNodes ("//html:input[@type='hidden']", nsmgr)) #endif { BaseControl bc = new BaseControl (); bc.Name = inputNode.Attributes["name"].Value; if (bc.Name == null || bc.Name == string.Empty) continue; if (inputNode.Attributes["value"] != null) bc.Value = inputNode.Attributes["value"].Value; else bc.Value = ""; Controls[bc.Name] = bc; } }
/// <summary> /// Adds a new control to the collection. If there is control with /// the same name, it will be overwritten. /// </summary> /// <param name="control">New control.</param> public void Add (BaseControl control) { this [control.Name] = control; }