HtmlForm.cs 4.8 KB

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