HtmlForm.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.Collections;
  7. using System.ComponentModel;
  8. using System.Text;
  9. using System.Web;
  10. using System.Web.UI;
  11. namespace System.Web.UI.HtmlControls{
  12. public class HtmlForm : HtmlContainerControl{
  13. // Unused
  14. //private static string SmartNavIncludeScriptKey = "SmartNavIncludeScript";
  15. public HtmlForm(): base("form"){}
  16. protected override void RenderAttributes(HtmlTextWriter writer){
  17. writer.WriteAttribute("name", Name);
  18. Attributes.Remove("name");
  19. writer.WriteAttribute("method", Method);
  20. Attributes.Remove("method");
  21. writer.WriteAttribute("action", Action, true);
  22. Attributes.Remove("action");
  23. if (Enctype != null){
  24. writer.WriteAttribute ("enctype", Enctype);
  25. Attributes.Remove ("enctype");
  26. }
  27. Hashtable onSubmit = Page.submitStatements;
  28. if (onSubmit != null && onSubmit.Count > 0){
  29. StringBuilder sb = new StringBuilder ();
  30. string prev = Attributes ["onsubmit"];
  31. if (prev != null){
  32. sb.Append (prev);
  33. Attributes.Remove ("onsubmit");
  34. }
  35. foreach (string s in onSubmit.Values)
  36. sb.Append (s);
  37. writer.WriteAttribute ("language", "javascript");
  38. writer.WriteAttribute ("onsubmit", sb.ToString ());
  39. }
  40. if (ID == null)
  41. writer.WriteAttribute ("id", ClientID);
  42. base.RenderAttributes (writer);
  43. }
  44. protected override void Render(HtmlTextWriter output){
  45. /*** Disabled smart navigation. We have no scripts - Gonzalo
  46. if (Page.SmartNavigation == false){
  47. base.Render (output);
  48. return;
  49. }
  50. ((IAttributeAccessor) this).SetAttribute("_smartNavigation","true");
  51. HttpBrowserCapabilities browserCap = Context.Request.Browser;
  52. if (browserCap.Browser.ToLower() != "ie" && browserCap.MajorVersion < 5){
  53. base.Render(output);
  54. return;
  55. }
  56. output.WriteLine("<IFRAME ID=_hifSmartNav NAME=_hifSmartNav STYLE=display:none ></IFRAME>");
  57. if (browserCap.MinorVersion < 0.5 && browserCap.MajorVersion != 5)
  58. Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNavIE5.js");
  59. else if (Page.IsPostBack) Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNav.js");
  60. */
  61. base.Render(output);
  62. }
  63. protected override void RenderChildren (HtmlTextWriter writer)
  64. {
  65. Page.OnFormRender (writer,ClientID);
  66. base.RenderChildren (writer);
  67. Page.OnFormPostRender (writer,ClientID);
  68. }
  69. protected override void OnInit(EventArgs e){
  70. base.OnInit(e);
  71. Page.RegisterViewStateHandler();
  72. }
  73. internal string Action{
  74. get{
  75. string executionFilePath = Context.Request.CurrentExecutionFilePath;
  76. string filePath = Context.Request.FilePath;
  77. string attr;
  78. if (String.ReferenceEquals(executionFilePath, filePath) == true){
  79. attr = filePath;
  80. int lastSlash = attr.LastIndexOf('/');
  81. if (lastSlash >= 0)
  82. attr = attr.Substring(lastSlash + 1);
  83. }
  84. else{
  85. attr = System.Web.Util.UrlUtils.MakeRelative(filePath,executionFilePath);
  86. }
  87. string queryString = Context.Request.QueryStringRaw;
  88. if (queryString != null && queryString.Length > 0)
  89. attr = String.Concat(attr, '?', queryString);
  90. return attr;
  91. }
  92. }
  93. [DefaultValue("")]
  94. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  95. [WebCategory("Behavior")]
  96. public string Enctype{
  97. get{
  98. string attr = Attributes["enctype"];
  99. if (attr != null){
  100. return attr;
  101. }
  102. return "";
  103. }
  104. set{
  105. Attributes["enctype"] = AttributeToString(value);
  106. }
  107. }
  108. [DefaultValue("")]
  109. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  110. [WebCategory("Behavior")]
  111. public string Method{
  112. get{
  113. string attr = Attributes["method"];
  114. if (attr != null){
  115. return attr;
  116. }
  117. return "post";
  118. }
  119. set{
  120. Attributes["method"] = AttributeToString(value);
  121. }
  122. }
  123. [DefaultValue("")]
  124. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  125. [WebCategory("Behavior")]
  126. public string Target{
  127. get{
  128. string attr = Attributes["target"];
  129. if (attr != null){
  130. return attr;
  131. }
  132. return String.Empty;
  133. }
  134. set{
  135. Attributes["target"] = AttributeToString(value);
  136. }
  137. }
  138. [DefaultValue("")]
  139. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  140. [WebCategory("Appearance")]
  141. public virtual string Name{
  142. get{
  143. return UniqueID;
  144. }
  145. set {
  146. }
  147. }
  148. } // class HtmlForm
  149. } // namespace System.Web.UI.HtmlControls