2
0

HtmlForm.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.Web;
  7. using System.Web.UI;
  8. namespace System.Web.UI.HtmlControls{
  9. public class HtmlForm : HtmlContainerControl{
  10. private static string SmartNavIncludeScriptKey = "SmartNavIncludeScript";
  11. public HtmlForm(): base("form"){}
  12. protected new void RenderAttributes(HtmlTextWriter writer){
  13. writer.WriteAttribute("name",RenderedName);
  14. Attributes.Remove("name");
  15. writer.WriteAttribute("method",Method);
  16. Attributes.Remove("method");
  17. writer.WriteAttribute("action",Action,true);
  18. Attributes.Remove("action");
  19. string clientOnSubmit = Page.ClientOnSubmitEvent;
  20. if (clientOnSubmit != null && clientOnSubmit.Length > 0){
  21. if (Attributes["onsubmit"] != null){
  22. clientOnSubmit = String.Concat(clientOnSubmit,Attributes["onsubmit"]);
  23. Attributes.Remove("onsubmit");
  24. }
  25. writer.WriteAttribute("language","javascript");
  26. writer.WriteAttribute("onsubmit",clientOnSubmit);
  27. }
  28. if (ID == null){
  29. writer.WriteAttribute("id",ClientID);
  30. }
  31. base.RenderAttributes(writer);
  32. }
  33. //TODO: adapt code for non-IE browsers
  34. protected override void Render(HtmlTextWriter output){
  35. if (Page.SmartNavigation == true){
  36. IAttributeAccessor.SetAttribute("_smartNavigation","true");
  37. HttpBrowserCapabilities browserCap = Context.Request.Browser;
  38. if (browserCap.Browser.ToLower() != "ie" && browserCap.MajorVersion < 5){
  39. base.Render(output);
  40. return;
  41. }
  42. output.WriteLine("<IFRAME ID=_hifSmartNav NAME=_hifSmartNav STYLE=display:none ></IFRAME>");
  43. if (browserCap.MinorVersion < 0.5 && browserCap.MajorVersion != 5)
  44. Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNavIE5.js");
  45. else if (Page.IsPostBack) Page.RegisterClientScriptFile("SmartNavIncludeScript","JScript","SmartNav.js");
  46. base.Render(output);
  47. }
  48. }
  49. protected override void RenderChildren(HtmlTextWriter writer){
  50. Page.OnFormRender(writer,ClientID);
  51. base.RenderChildren(writer);
  52. Page.OnFormPostRender(writer,ClientID);
  53. }
  54. protected override void OnInit(EventArgs e){
  55. base.OnInit(e);
  56. Page.RegisterViewStateHandler();
  57. }
  58. internal string Action{
  59. get{
  60. string executionFilePath = Context.Request.CurrentExecutionFilePath;
  61. string filePath = Context.Request.FilePath;
  62. string attr;
  63. if (String.ReferenceEquals(executionFilePath, filePath) == true){
  64. attr = filePath;
  65. int lastSlash = attr.LastIndexOf('/');
  66. if (lastSlash >= 0)
  67. attr = attr.Substring(lastSlash + 1);
  68. }
  69. else{
  70. attr = Util.UrlPath.MakeRelative(filePath,executionFilePath);
  71. }
  72. string queryString = Context.Request.QueryStringText;
  73. if (queryString != null && queryString.Length > 0)
  74. attr = String.Concat(attr, '?', queryString);
  75. return attr;
  76. }
  77. }
  78. public string EncType{
  79. get{
  80. string attr = Attributes["enctype"];
  81. if (attr != null){
  82. return attr;
  83. }
  84. return null;
  85. }
  86. set{
  87. Attributes["enctype"] = AttributeToString(value);
  88. }
  89. }
  90. public string Method{
  91. get{
  92. string attr = Attributes["method"];
  93. if (attr != null){
  94. return attr;
  95. }
  96. return "post";
  97. }
  98. set{
  99. Attributes["method"] = AttributeToString(value);
  100. }
  101. }
  102. public string Target{
  103. get{
  104. string attr = Attributes["target"];
  105. if (attr != null){
  106. return attr;
  107. }
  108. return String.Empty;
  109. }
  110. set{
  111. Attributes["target"] = AttributeToString(value);
  112. }
  113. }
  114. public string Name{
  115. get{
  116. string attr = Attributes["name"];
  117. if (attr != null){
  118. return attr;
  119. }
  120. return String.Empty;
  121. }
  122. }
  123. internal string RenderedName{
  124. get{
  125. string attr = Name;
  126. if (attr.Length > 0){
  127. return attr;
  128. }
  129. return UniqueID;
  130. }
  131. }
  132. } // class HtmlForm
  133. } // namespace System.Web.UI.HtmlControls