HtmlForm.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. //
  2. // System.Web.UI.HtmlControls.HtmlForm.cs
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using System.ComponentModel;
  29. using System.Collections.Specialized;
  30. namespace System.Web.UI.HtmlControls
  31. {
  32. public class HtmlForm : HtmlContainerControl
  33. {
  34. public HtmlForm () : base ("form")
  35. {
  36. }
  37. #if NET_2_0
  38. [DefaultValue ("")]
  39. [MonoTODO]
  40. public string DefaultButton
  41. {
  42. get {
  43. throw new NotImplementedException ();
  44. }
  45. set {
  46. throw new NotImplementedException ();
  47. }
  48. }
  49. [DefaultValue ("")]
  50. [MonoTODO]
  51. public string DefaultFocus
  52. {
  53. get {
  54. throw new NotImplementedException ();
  55. }
  56. set {
  57. throw new NotImplementedException ();
  58. }
  59. }
  60. #endif
  61. [DefaultValue ("")]
  62. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  63. public string Enctype
  64. {
  65. get {
  66. string enc = Attributes["enctype"];
  67. if (enc == null) {
  68. return (String.Empty);
  69. }
  70. return (enc);
  71. }
  72. set {
  73. if (value == null) {
  74. Attributes.Remove ("enctype");
  75. } else {
  76. Attributes["enctype"] = value;
  77. }
  78. }
  79. }
  80. [DefaultValue ("")]
  81. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  82. public string Method
  83. {
  84. get {
  85. string method = Attributes["method"];
  86. if (method == null) {
  87. return ("post");
  88. }
  89. return (method);
  90. }
  91. set {
  92. if (value == null) {
  93. Attributes.Remove ("method");
  94. } else {
  95. Attributes["method"] = value;
  96. }
  97. }
  98. }
  99. [DefaultValue ("")]
  100. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  101. #if NET_2_0
  102. public virtual
  103. #else
  104. public
  105. #endif
  106. string Name
  107. {
  108. get {
  109. string name = Attributes["name"];
  110. if (name == null) {
  111. return (UniqueID);
  112. }
  113. return (name);
  114. }
  115. set {
  116. if (value == null) {
  117. Attributes.Remove ("name");
  118. } else {
  119. Attributes["name"] = value;
  120. }
  121. }
  122. }
  123. #if NET_2_0
  124. [DefaultValue (false)]
  125. [MonoTODO]
  126. public virtual bool SubmitDisabledControls
  127. {
  128. get {
  129. throw new NotImplementedException ();
  130. }
  131. set {
  132. throw new NotImplementedException ();
  133. }
  134. }
  135. #endif
  136. [DefaultValue ("")]
  137. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  138. public string Target
  139. {
  140. get {
  141. string target = Attributes["target"];
  142. if (target == null) {
  143. return (String.Empty);
  144. }
  145. return (target);
  146. }
  147. set {
  148. if (value == null) {
  149. Attributes.Remove ("target");
  150. } else {
  151. Attributes["target"] = value;
  152. }
  153. }
  154. }
  155. #if NET_2_0
  156. public override
  157. #else
  158. // New in NET1.1 sp1
  159. public new
  160. #endif
  161. string UniqueID
  162. {
  163. get {
  164. return base.UniqueID;
  165. }
  166. }
  167. #if NET_2_0
  168. [MonoTODO]
  169. protected override ControlCollection CreateControlCollection ()
  170. {
  171. return base.CreateControlCollection ();
  172. }
  173. #endif
  174. #if NET_2_0
  175. protected internal
  176. #else
  177. protected
  178. #endif
  179. override void OnInit (EventArgs e)
  180. {
  181. Page.RegisterViewStateHandler ();
  182. base.OnInit (e);
  183. }
  184. #if NET_2_0
  185. [MonoTODO("Probably something about validators here")]
  186. protected internal override void OnPreRender (EventArgs e)
  187. {
  188. base.OnPreRender(e);
  189. }
  190. #endif
  191. protected override void RenderAttributes (HtmlTextWriter w)
  192. {
  193. /* Need to always render: name, method, action
  194. * and id
  195. */
  196. string action = Page.Request.FilePath;
  197. string query = Page.Request.QueryStringRaw;
  198. if (query != null && query.Length > 0) {
  199. action += "?" + query;
  200. }
  201. w.WriteAttribute ("name", Name);
  202. w.WriteAttribute ("method", Method);
  203. w.WriteAttribute ("action", action);
  204. if (ID == null) {
  205. /* If ID != null then HtmlControl will
  206. * write the id attribute
  207. */
  208. w.WriteAttribute ("id", ClientID);
  209. Attributes.Remove ("id");
  210. }
  211. string submit = Page.GetSubmitStatements ();
  212. if (submit != null && submit != "")
  213. w.WriteAttribute ("onsubmit", submit);
  214. /* enctype and target should not be written if
  215. * they are empty
  216. */
  217. string enctype = Enctype;
  218. if (enctype != null && enctype != "") {
  219. w.WriteAttribute ("enctype", enctype);
  220. }
  221. string target = Target;
  222. if (target != null && target != "") {
  223. w.WriteAttribute ("target", target);
  224. }
  225. /* Now remove them from the hash so the base
  226. * RenderAttributes can do all the rest
  227. */
  228. Attributes.Remove ("name");
  229. Attributes.Remove ("method");
  230. Attributes.Remove ("enctype");
  231. Attributes.Remove ("target");
  232. base.RenderAttributes (w);
  233. }
  234. #if NET_2_0
  235. protected internal
  236. #else
  237. protected
  238. #endif
  239. override void RenderChildren (HtmlTextWriter w)
  240. {
  241. Page.OnFormRender (w, ClientID);
  242. base.RenderChildren (w);
  243. Page.OnFormPostRender (w, ClientID);
  244. }
  245. #if NET_2_0
  246. /* According to corcompare */
  247. [MonoTODO]
  248. public override void RenderControl (HtmlTextWriter w)
  249. {
  250. base.RenderControl (w);
  251. }
  252. #endif
  253. #if NET_2_0
  254. protected internal
  255. #else
  256. protected
  257. #endif
  258. override void Render (HtmlTextWriter w)
  259. {
  260. base.Render (w);
  261. }
  262. }
  263. }