2
0

HtmlForm.cs 3.9 KB

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