HtmlControl.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // System.Web.UI.HtmlControls.HtmlControl.cs
  3. //
  4. // Author
  5. // Bob Smith <[email protected]>
  6. //
  7. //
  8. // (C) Bob Smith
  9. //
  10. using System;
  11. using System.ComponentModel;
  12. using System.ComponentModel.Design;
  13. using System.Globalization;
  14. using System.Web;
  15. using System.Web.UI;
  16. namespace System.Web.UI.HtmlControls{
  17. [ToolboxItem(false)]
  18. [Designer ("System.Web.UI.Design.HtmlIntrinsicControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  19. public abstract class HtmlControl : Control, IAttributeAccessor
  20. {
  21. internal string _tagName;
  22. private AttributeCollection _attributes;
  23. public HtmlControl() : this ("span") {}
  24. public HtmlControl(string tag)
  25. {
  26. _tagName = tag;
  27. }
  28. protected override ControlCollection CreateControlCollection ()
  29. {
  30. return new EmptyControlCollection (this);
  31. }
  32. internal static string AttributeToString(int n){
  33. if (n != -1)return n.ToString(NumberFormatInfo.InvariantInfo);
  34. return null;
  35. }
  36. internal static string AttributeToString(string s){
  37. if (s != null && s.Length != 0) return s;
  38. return null;
  39. }
  40. internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){
  41. string attr = Attributes[attribName];
  42. if (attr != null){
  43. if (attr.Length != 0){
  44. try{
  45. attr = ResolveUrl(attr);
  46. }
  47. catch (Exception e) {
  48. throw new HttpException(attribName + " property had malformed url");
  49. }
  50. writer.WriteAttribute(attribName, attr);
  51. Attributes.Remove(attribName);
  52. }
  53. }
  54. }
  55. string System.Web.UI.IAttributeAccessor.GetAttribute(string name){
  56. return Attributes[name];
  57. }
  58. void System.Web.UI.IAttributeAccessor.SetAttribute(string name, string value){
  59. Attributes[name] = value;
  60. }
  61. protected virtual void RenderBeginTag (HtmlTextWriter writer)
  62. {
  63. writer.WriteBeginTag (TagName);
  64. RenderAttributes (writer);
  65. writer.Write ('>');
  66. }
  67. protected override void Render (HtmlTextWriter writer)
  68. {
  69. RenderBeginTag (writer);
  70. }
  71. protected virtual void RenderAttributes(HtmlTextWriter writer){
  72. if (ID != null){
  73. writer.WriteAttribute("id",ClientID);
  74. }
  75. Attributes.Render(writer);
  76. }
  77. [Browsable(false)]
  78. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  79. public AttributeCollection Attributes
  80. {
  81. get {
  82. if (_attributes == null)
  83. _attributes = new AttributeCollection (ViewState);
  84. return _attributes;
  85. }
  86. }
  87. [DefaultValue("")]
  88. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  89. [WebCategory("Behavior")]
  90. public bool Disabled
  91. {
  92. get {
  93. string disableAttr = Attributes["disabled"] as string;
  94. return (disableAttr != null);
  95. }
  96. set {
  97. if (!value)
  98. Attributes.Remove ("disabled");
  99. else
  100. Attributes["disabled"] = "disabled";
  101. }
  102. }
  103. [Browsable(false)]
  104. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  105. public CssStyleCollection Style
  106. {
  107. get { return Attributes.CssStyle; }
  108. }
  109. [DefaultValue("")]
  110. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  111. [WebCategory("Appearance")]
  112. public virtual string TagName
  113. {
  114. get { return _tagName; }
  115. }
  116. protected override bool ViewStateIgnoresCase
  117. {
  118. get {
  119. return true;
  120. }
  121. }
  122. }
  123. }