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.Web;
  9. using System.Web.UI;
  10. using System.Web.Util;
  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. string submitStatements = Page.ClientScript.WriteSubmitStatements ();
  28. if (submitStatements != null) {
  29. string prev = Attributes ["onsubmit"];
  30. if (prev != null) {
  31. submitStatements = prev + submitStatements;
  32. Attributes.Remove ("onsubmit");
  33. }
  34. writer.WriteAttribute ("language", "javascript");
  35. writer.WriteAttribute ("onsubmit", submitStatements);
  36. }
  37. if (ID == null)
  38. writer.WriteAttribute ("id", ClientID);
  39. base.RenderAttributes (writer);
  40. }
  41. protected override void Render(HtmlTextWriter output){
  42. /*** Disabled smart navigation. We have no scripts - Gonzalo
  43. if (Page.SmartNavigation == false){
  44. base.Render (output);
  45. return;
  46. }
  47. ((IAttributeAccessor) this).SetAttribute("_smartNavigation","true");
  48. HttpBrowserCapabilities browserCap = Context.Request.Browser;
  49. if (browserCap.Browser.ToLower() != "ie" && browserCap.MajorVersion < 5){
  50. base.Render(output);
  51. return;
  52. }
  53. output.WriteLine("<IFRAME ID=_hifSmartNav NAME=_hifSmartNav STYLE=display:none ></IFRAME>");
  54. if (browserCap.MinorVersion < 0.5 && browserCap.MajorVersion != 5)
  55. Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNavIE5.js");
  56. else if (Page.IsPostBack) Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNav.js");
  57. */
  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. #if NET_2_0
  70. Page.RegisterForm (this);
  71. #endif
  72. }
  73. internal string Action {
  74. get{
  75. string executionFilePath = Context.Request.CurrentExecutionFilePath;
  76. string filePath = Context.Request.FilePath;
  77. string attr;
  78. if (executionFilePath == filePath) {
  79. attr = filePath;
  80. int lastSlash = attr.LastIndexOf('/');
  81. if (lastSlash >= 0)
  82. attr = attr.Substring(lastSlash + 1);
  83. } else {
  84. attr = UrlUtils.MakeRelative (executionFilePath, UrlUtils.GetDirectory (filePath));
  85. if (attr == null)
  86. attr = executionFilePath;
  87. }
  88. string queryString = Context.Request.QueryStringRaw;
  89. if (queryString != null && queryString.Length > 0)
  90. attr = String.Concat(attr, '?', queryString);
  91. return attr;
  92. }
  93. }
  94. [DefaultValue("")]
  95. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  96. [WebCategory("Behavior")]
  97. public string Enctype{
  98. get{
  99. string attr = Attributes["enctype"];
  100. if (attr != null){
  101. return attr;
  102. }
  103. return "";
  104. }
  105. set{
  106. Attributes["enctype"] = AttributeToString(value);
  107. }
  108. }
  109. [DefaultValue("")]
  110. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  111. [WebCategory("Behavior")]
  112. public string Method{
  113. get{
  114. string attr = Attributes["method"];
  115. if (attr != null){
  116. return attr;
  117. }
  118. return "post";
  119. }
  120. set{
  121. Attributes["method"] = AttributeToString(value);
  122. }
  123. }
  124. [DefaultValue("")]
  125. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  126. [WebCategory("Behavior")]
  127. public string Target{
  128. get{
  129. string attr = Attributes["target"];
  130. if (attr != null){
  131. return attr;
  132. }
  133. return String.Empty;
  134. }
  135. set{
  136. Attributes["target"] = AttributeToString(value);
  137. }
  138. }
  139. [DefaultValue("")]
  140. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  141. [WebCategory("Appearance")]
  142. public virtual string Name{
  143. get{
  144. return UniqueID;
  145. }
  146. set {
  147. }
  148. }
  149. } // class HtmlForm
  150. } // namespace System.Web.UI.HtmlControls