2
0

HtmlControl.cs 2.6 KB

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