HtmlControl.cs 3.1 KB

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