2 // System.Web.UI.HtmlControls.HtmlForm.cs
5 // Dick Porter <dick@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
30 using System.Collections.Specialized;
31 using System.Security.Permissions;
32 using System.Web.Util;
33 using System.Web.UI.WebControls;
35 namespace System.Web.UI.HtmlControls
38 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 public class HtmlForm : HtmlContainerControl
44 public HtmlForm () : base ("form")
49 string defaultbutton = "";
51 public string DefaultButton
57 defaultbutton = (value == null ? "" : value);
61 string defaultfocus = "";
63 public string DefaultFocus
69 defaultfocus = (value == null ? "" : value);
75 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 string enc = Attributes["enctype"];
82 return (String.Empty);
89 Attributes.Remove ("enctype");
91 Attributes["enctype"] = value;
97 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
101 string method = Attributes["method"];
103 if ((method == null) || (method.Length == 0)) {
111 Attributes.Remove ("method");
113 Attributes["method"] = value;
119 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
120 public virtual string Name
126 /* why am i here? I do nothing. */
131 bool submitdisabledcontrols = false;
132 [DefaultValue (false)]
133 public virtual bool SubmitDisabledControls
136 return submitdisabledcontrols;
139 submitdisabledcontrols = value;
145 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
149 string target = Attributes["target"];
151 if (target == null) {
152 return (String.Empty);
159 Attributes.Remove ("target");
161 Attributes["target"] = value;
166 public override string UniqueID {
168 return base.UniqueID;
173 [MonoTODO ("why override?")]
174 protected override ControlCollection CreateControlCollection ()
176 return base.CreateControlCollection ();
185 override void OnInit (EventArgs e)
188 Page.RegisterViewStateHandler ();
191 Page.RegisterForm (this);
198 internal bool DetermineRenderUplevel ()
200 /* this bit is c&p'ed from BaseValidator.DetermineRenderUplevel */
202 if (Page != null && Page.Request != null)
204 /* From someplace on the web: "JavaScript 1.2
205 * and later (also known as ECMAScript) has
206 * built-in support for regular
208 ((Page.Request.Browser.EcmaScriptVersion.Major == 1
209 && Page.Request.Browser.EcmaScriptVersion.Minor >= 2)
210 || (Page.Request.Browser.EcmaScriptVersion.Major > 1))
212 /* document.getElementById, .getAttribute,
213 * etc, are all DOM level 1. I don't think we
214 * use anything in level 2.. */
215 && Page.Request.Browser.W3CDomVersion.Major >= 1);
218 /* this can happen with a fake Page in nunit
219 * tests, since Page.Context == null */
226 protected internal override void OnPreRender (EventArgs e)
232 protected override void RenderAttributes (HtmlTextWriter w)
234 /* Need to always render: name, method, action
239 string file_path = Page.Request.FilePath;
240 string current_path = Page.Request.CurrentExecutionFilePath;
241 if (file_path == current_path) {
242 // Just the filename will do
243 action = UrlUtils.GetFile (file_path);
245 // Fun. We need to make cookieless sessions work, so no
246 // absolute paths here.
247 Uri current_uri = new Uri ("http://host" + current_path);
248 Uri fp_uri = new Uri ("http://host" + file_path);
249 action = fp_uri.MakeRelative (current_uri);
252 action += Page.Request.QueryStringRaw;
254 vmw.@internal.j2ee.IPortletRenderResponse resp = GetRenderResponse();
256 action = resp.createActionURL(action);
259 w.WriteAttribute ("name", Name);
261 w.WriteAttribute ("method", Method);
262 w.WriteAttribute ("action", action);
265 /* If ID != null then HtmlControl will
266 * write the id attribute
268 w.WriteAttribute ("id", ClientID);
269 Attributes.Remove ("id");
272 string submit = Page.GetSubmitStatements ();
273 if (submit != null && submit != "") {
274 Attributes.Remove ("onsubmit");
275 w.WriteAttribute ("onsubmit", submit);
278 /* enctype and target should not be written if
281 string enctype = Enctype;
282 if (enctype != null && enctype != "") {
283 w.WriteAttribute ("enctype", enctype);
286 string target = Target;
287 if (target != null && target != "") {
288 w.WriteAttribute ("target", target);
292 string defaultbutton = DefaultButton;
293 if (defaultbutton != null && defaultbutton != "") {
294 Control c = FindControl (defaultbutton);
296 if (c == null || !(c is IButtonControl))
297 throw new InvalidOperationException(String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.",
302 /* Now remove them from the hash so the base
303 * RenderAttributes can do all the rest
305 Attributes.Remove ("method");
306 Attributes.Remove ("enctype");
307 Attributes.Remove ("target");
309 base.RenderAttributes (w);
317 override void RenderChildren (HtmlTextWriter w)
320 Page.RegisterViewStateHandler ();
322 Page.RegisterForm (this);
325 Page.OnFormRender (w, ClientID);
326 base.RenderChildren (w);
327 Page.OnFormPostRender (w, ClientID);
331 /* According to corcompare */
332 [MonoTODO ("why override?")]
333 public override void RenderControl (HtmlTextWriter w)
335 base.RenderControl (w);
344 override void Render (HtmlTextWriter w)