2
0

HtmlControl.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.Globalization;
  12. using System.Web;
  13. using System.Web.UI;
  14. namespace System.Web.UI.HtmlControls{
  15. public abstract class HtmlControl : Control, IAttributeAccessor
  16. {
  17. private string _tagName = "span";
  18. //TODO: Is this correct, or is the StateBag really the ViewState?
  19. private AttributeCollection _attributes = new AttributeCollection(new StateBag(true));
  20. private bool _disabled = false;
  21. public HtmlControl(){}
  22. public HtmlControl(string tag)
  23. {
  24. if(tag != null && tag != "") _tagName = tag;
  25. }
  26. internal static string AttributeToString(int n){
  27. if (n != -1)return n.ToString(NumberFormatInfo.InvariantInfo);
  28. return null;
  29. }
  30. internal static string AttributeToString(string s){
  31. if (s != null && s.Length != 0) return s;
  32. return null;
  33. }
  34. internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){
  35. string attr = Attributes[attribName];
  36. if (attr != null){
  37. if (attr.Length != 0){
  38. try{
  39. attr = ResolveUrl(attr);
  40. }
  41. catch (Exception e) {
  42. throw new HttpException(attribName + " property had malformed url");
  43. }
  44. writer.WriteAttribute(attribName, attr);
  45. Attributes.Remove(attribName);
  46. }
  47. }
  48. }
  49. string System.Web.UI.IAttributeAccessor.GetAttribute(string name){
  50. return Attributes[name];
  51. }
  52. void System.Web.UI.IAttributeAccessor.SetAttribute(string name, string value){
  53. Attributes[name] = value;
  54. }
  55. protected virtual void RenderAttributes(HtmlTextWriter writer){
  56. if (ID != null){
  57. writer.WriteAttribute("id",ClientID);
  58. }
  59. Attributes.Render(writer);
  60. }
  61. public AttributeCollection Attributes
  62. {
  63. get
  64. {
  65. return _attributes;
  66. }
  67. }
  68. public bool Disabled
  69. {
  70. get
  71. {
  72. return _disabled;
  73. }
  74. set
  75. {
  76. _disabled = value;
  77. }
  78. }
  79. public CssStyleCollection Style
  80. {
  81. get
  82. {
  83. return _attributes.CssStyle;
  84. }
  85. }
  86. public virtual string TagName
  87. {
  88. get
  89. {
  90. return _tagName;
  91. }
  92. }
  93. }
  94. }