2
0

Image.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Image
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2001)
  12. */
  13. using System;
  14. using System.Web;
  15. using System.Web.UI;
  16. using System.ComponentModel;
  17. namespace System.Web.UI.WebControls
  18. {
  19. [DefaultProperty("ImageUrl")]
  20. [ParseChildren(true)]
  21. [PersistChildren(false)]
  22. public class Image : WebControl
  23. {
  24. public Image(): base(HtmlTextWriterTag.Img)
  25. {
  26. }
  27. public virtual string AlternateText
  28. {
  29. get
  30. {
  31. object o = ViewState["AlternateText"];
  32. if(o!=null)
  33. return (string)o;
  34. return String.Empty;
  35. }
  36. set
  37. {
  38. ViewState["AlternateText"] = value;
  39. }
  40. }
  41. public override bool Enabled
  42. {
  43. get
  44. {
  45. return base.Enabled;
  46. }
  47. set
  48. {
  49. base.Enabled = value;
  50. }
  51. }
  52. public override FontInfo Font
  53. {
  54. get
  55. {
  56. return base.Font;
  57. }
  58. }
  59. public virtual ImageAlign ImageAlign
  60. {
  61. get
  62. {
  63. object o = ViewState["ImageAlign"];
  64. if(o!=null)
  65. return (ImageAlign)o;
  66. return ImageAlign.NotSet;
  67. }
  68. set
  69. {
  70. ViewState["ImageAlign"] = value;
  71. }
  72. }
  73. public virtual string ImageUrl
  74. {
  75. get
  76. {
  77. object o = ViewState["ImageUrl"];
  78. if(o!=null)
  79. return (string)o;
  80. return String.Empty;
  81. }
  82. set
  83. {
  84. ViewState["ImageUrl"] = value;
  85. }
  86. }
  87. protected override void AddAttributesToRender(HtmlTextWriter writer)
  88. {
  89. base.AddAttributesToRender(writer);
  90. if(ImageUrl.Length > 0)
  91. {
  92. writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveUrl(ImageUrl));
  93. }
  94. if(AlternateText.Length > 0)
  95. {
  96. writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
  97. }
  98. if(BorderWidth.IsEmpty)
  99. {
  100. writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
  101. }
  102. if(ImageAlign != ImageAlign.NotSet)
  103. {
  104. writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(ImageAlign), ImageAlign, "G"));
  105. }
  106. }
  107. protected override void RenderContents(HtmlTextWriter writer)
  108. {
  109. }
  110. }
  111. }