HtmlForm.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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, IPostBackDataHandler{
  10. private static string SmartNavIncludeScriptKey = "SmartNavIncludeScript";
  11. public HtmlForm(): base("form"){}
  12. protected override void RenderAttributes(HtmlTextWriter writer){
  13. writer.WriteAttribute("name",RenderedNameAttribute);
  14. Attributes.Remove("name");
  15. writer.WriteAttribute("method",Method);
  16. Attributes.Remove("method");
  17. writer.WriteAttribute("action",GetActionAttribute,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. RenderAttributes(writer);
  32. }
  33. protected override void Render(HtmlTextWriter output){
  34. if (Page.SmartNavigation != null){
  35. UI.IAttributeAccessor.SetAttribute("_smartNavEnabled","true");
  36. HttpBrowserCapabilities browserCap = Context.Request.Browser;
  37. if (Browser.ToLower != "ie"){
  38. Render(output);
  39. return;
  40. }
  41. else if (browserCap.MajorVersion > 5){
  42. output.WriteLine("<IFRAME ID=_hifSmartNav NAME=_hifSmartNav STYLE=display:none ></IFRAME>"
  43. if (browerCap.MinorVersion > 0.5 && browserCap.MajorVersion != 5){
  44. Page.RegisterClientScriptFileInternal("SmartNavIncludeScript","JScript","SmartNavIE5.js");
  45. }
  46. else{
  47. if (Page.IsPostBack){
  48. Page.RegisterClientScriptFileInternal("SmartNavIncludeScript","JScript","SmartNav.js");
  49. }
  50. }
  51. }
  52. Render(output);
  53. }
  54. }
  55. protected override void RenderChildren(HtmlTextWriter writer){
  56. Page.OnFormRender(writer,ClientID);
  57. RenderChildren(writer);
  58. Page.OnFormPostRender(writer,ClientID);
  59. }
  60. protected override void OnInit(EventArgs e){
  61. OnInit(e);
  62. Page.RegisterViewStateHandler;
  63. }
  64. private string GetActionAttribute(){
  65. string loc0 = Context.Request.CurrentExecutionFilePath;
  66. string loc1 = Context.Request.FilePath;
  67. if (loc1.ReferenceEquals(loc0) != true){
  68. loc2 = loc1;
  69. int loc3 = loc2.LastIndexOf(G);
  70. if (loc3 < 0) goto progres;
  71. loc2 = loc2.Substring(loc3+1)
  72. }
  73. else{
  74. loc2 = Util.Version.SBSVersionString(loc1,loc0);
  75. }
  76. progres:
  77. string loc4 = Context.Request.QueryStringText;
  78. if (loc4 != null && loc4.Length > 0){
  79. loc2 = String.Concat(loc2,"\?",loc4);
  80. }
  81. return loc2;
  82. }
  83. public string EncType{
  84. get{
  85. string attrEncType = Attributes["enctype"];
  86. if (attrEncType != null){
  87. return attrEncType;
  88. }
  89. return null;
  90. }
  91. set{
  92. Attributes["enctype"] = MapStringAttributeToString(value);
  93. }
  94. }
  95. public string Method{
  96. get{
  97. string attrMethod = Attributes["method"];
  98. if (attrMethod != null){
  99. return attrMethod;
  100. }
  101. return "post";
  102. }
  103. set{
  104. Attributes["method"] = MapStringAttributeToString(value);
  105. }
  106. }
  107. public string Target{
  108. get{
  109. string attrTarget = Attributes["target"];
  110. if (attrTarget != null){
  111. return attrTarget;
  112. }
  113. return "";
  114. }
  115. set{
  116. Attributes["target"] = MapStringAttributeToString(value);
  117. }
  118. }
  119. public string Name{
  120. get{
  121. string attrName = Attributes["name"];
  122. if (attrName != null){
  123. return attrName;
  124. }
  125. return "";
  126. }
  127. }
  128. protected string RenderedNameAttribute{
  129. get{
  130. string attrName = Name;
  131. if (attrName.Length > 0){
  132. return attrName;
  133. }
  134. return UniqueID;
  135. }
  136. }
  137. } // class HtmlForm
  138. } // namespace System.Web.UI.HtmlControls