HtmlForm.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. if (Page.SmartNavigation == false){
  46. base.Render (output);
  47. return;
  48. }
  49. ((IAttributeAccessor) this).SetAttribute("_smartNavigation","true");
  50. HttpBrowserCapabilities browserCap = Context.Request.Browser;
  51. if (browserCap.Browser.ToLower() != "ie" && browserCap.MajorVersion < 5){
  52. base.Render(output);
  53. return;
  54. }
  55. output.WriteLine("<IFRAME ID=_hifSmartNav NAME=_hifSmartNav STYLE=display:none ></IFRAME>");
  56. if (browserCap.MinorVersion < 0.5 && browserCap.MajorVersion != 5)
  57. Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNavIE5.js");
  58. else if (Page.IsPostBack) Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNav.js");
  59. base.Render(output);
  60. }
  61. protected override void RenderChildren (HtmlTextWriter writer)
  62. {
  63. Page.OnFormRender (writer,ClientID);
  64. base.RenderChildren (writer);
  65. Page.OnFormPostRender (writer,ClientID);
  66. }
  67. protected override void OnInit(EventArgs e){
  68. base.OnInit(e);
  69. Page.RegisterViewStateHandler();
  70. }
  71. internal string Action{
  72. get{
  73. string executionFilePath = Context.Request.CurrentExecutionFilePath;
  74. string filePath = Context.Request.FilePath;
  75. string attr;
  76. if (String.ReferenceEquals(executionFilePath, filePath) == true){
  77. attr = filePath;
  78. int lastSlash = attr.LastIndexOf('/');
  79. if (lastSlash >= 0)
  80. attr = attr.Substring(lastSlash + 1);
  81. }
  82. else{
  83. attr = System.Web.Util.UrlUtils.MakeRelative(filePath,executionFilePath);
  84. }
  85. string queryString = Context.Request.QueryStringRaw;
  86. if (queryString != null && queryString.Length > 0)
  87. attr = String.Concat(attr, '?', queryString);
  88. return attr;
  89. }
  90. }
  91. [DefaultValue("")]
  92. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  93. [WebCategory("Behavior")]
  94. public string Enctype{
  95. get{
  96. string attr = Attributes["enctype"];
  97. if (attr != null){
  98. return attr;
  99. }
  100. return "";
  101. }
  102. set{
  103. Attributes["enctype"] = AttributeToString(value);
  104. }
  105. }
  106. [DefaultValue("")]
  107. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  108. [WebCategory("Behavior")]
  109. public string Method{
  110. get{
  111. string attr = Attributes["method"];
  112. if (attr != null){
  113. return attr;
  114. }
  115. return "post";
  116. }
  117. set{
  118. Attributes["method"] = AttributeToString(value);
  119. }
  120. }
  121. [DefaultValue("")]
  122. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  123. [WebCategory("Behavior")]
  124. public string Target{
  125. get{
  126. string attr = Attributes["target"];
  127. if (attr != null){
  128. return attr;
  129. }
  130. return String.Empty;
  131. }
  132. set{
  133. Attributes["target"] = AttributeToString(value);
  134. }
  135. }
  136. [DefaultValue("")]
  137. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  138. [WebCategory("Appearance")]
  139. public virtual string Name{
  140. get{
  141. return UniqueID;
  142. }
  143. set {
  144. }
  145. }
  146. } // class HtmlForm
  147. } // namespace System.Web.UI.HtmlControls