HtmlControl.cs 3.2 KB

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