HyperLink.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // System.Web.UI.WebControls.Label.cs
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // TODO: Are we missing something in LoadViewState?
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.ComponentModel;
  31. using System.Web.UI;
  32. namespace System.Web.UI.WebControls {
  33. [ControlBuilder(typeof(HyperLinkControlBuilder))]
  34. [DataBindingHandler("System.Web.UI.Design.HyperLinkDataBindingHandler, " + Consts.AssemblySystem_Design)]
  35. [ParseChildren (false)]
  36. #if NET_2_0
  37. [ToolboxData("<{0}:HyperLink runat=\"server\">HyperLink</{0}:HyperLink>")]
  38. #else
  39. [ToolboxData("<{0}:HyperLink runat=server>HyperLink</{0}:HyperLink>")]
  40. #endif
  41. [DefaultProperty("Text")]
  42. [Designer("System.Web.UI.Design.WebControls.HyperLinkDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  43. public class HyperLink : WebControl {
  44. public HyperLink () : base (HtmlTextWriterTag.A)
  45. {
  46. }
  47. protected override void AddAttributesToRender (HtmlTextWriter w)
  48. {
  49. base.AddAttributesToRender (w);
  50. // add attributes - only if they're not empty
  51. string s = NavigateUrl;
  52. if (s.Length > 0)
  53. w.AddAttribute (HtmlTextWriterAttribute.Href, ResolveUrl (s));
  54. s = Target;
  55. if (s.Length > 0)
  56. w.AddAttribute (HtmlTextWriterAttribute.Target, s);
  57. }
  58. protected override void AddParsedSubObject (object obj)
  59. {
  60. if (HasControls ()) {
  61. base.AddParsedSubObject (obj);
  62. return;
  63. }
  64. LiteralControl lc = obj as LiteralControl;
  65. if (lc == null) {
  66. string s = Text;
  67. if (s.Length != 0) {
  68. Text = null;
  69. Controls.Add (new LiteralControl (s));
  70. }
  71. base.AddParsedSubObject (obj);
  72. } else {
  73. Text = lc.Text;
  74. }
  75. }
  76. [MonoTODO ("Why override?")]
  77. protected override void LoadViewState (object savedState)
  78. {
  79. base.LoadViewState (savedState);
  80. }
  81. #if NET_2_0
  82. protected internal
  83. #else
  84. protected
  85. #endif
  86. override void RenderContents (HtmlTextWriter w)
  87. {
  88. if (HasControls ())
  89. base.RenderContents (w);
  90. else if (ImageUrl != "") {
  91. w.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
  92. #if NET_2_0
  93. string s = Text;
  94. if (s.Length > 0)
  95. w.AddAttribute (HtmlTextWriterAttribute.Alt, s);
  96. w.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
  97. #else
  98. w.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
  99. w.AddAttribute (HtmlTextWriterAttribute.Border, "0");
  100. #endif
  101. w.RenderBeginTag (HtmlTextWriterTag.Img);
  102. w.RenderEndTag ();
  103. } else {
  104. w.Write (Text);
  105. }
  106. }
  107. [Bindable(true)]
  108. [DefaultValue("")]
  109. [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
  110. #if NET_2_0
  111. [UrlProperty]
  112. #endif
  113. [WebSysDescription ("")]
  114. [WebCategory ("Appearance")]
  115. public virtual string ImageUrl {
  116. get {
  117. return ViewState.GetString ("ImageUrl", "");
  118. }
  119. set {
  120. ViewState ["ImageUrl"] = value;
  121. }
  122. }
  123. [Bindable(true)]
  124. [DefaultValue("")]
  125. [Editor("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
  126. #if NET_2_0
  127. [UrlProperty]
  128. #endif
  129. [WebSysDescription ("")]
  130. [WebCategory ("Navigation")]
  131. public string NavigateUrl {
  132. get {
  133. return ViewState.GetString ("NavigateUrl", "");
  134. }
  135. set {
  136. ViewState ["NavigateUrl"] = value;
  137. }
  138. }
  139. #if ONLY_1_1
  140. [Bindable(true)]
  141. #endif
  142. [DefaultValue("")]
  143. [TypeConverter(typeof(System.Web.UI.WebControls.TargetConverter))]
  144. [WebSysDescription ("")]
  145. [WebCategory ("Navigation")]
  146. public string Target {
  147. get {
  148. return ViewState.GetString ("Target", "");
  149. }
  150. set {
  151. ViewState ["Target"] = value;
  152. }
  153. }
  154. [Bindable(true)]
  155. [DefaultValue("")]
  156. [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
  157. #if NET_2_0
  158. [Localizable (true)]
  159. #endif
  160. [WebSysDescription ("")]
  161. [WebCategory ("Appearance")]
  162. public virtual string Text {
  163. get {
  164. return ViewState.GetString ("Text", "");
  165. }
  166. set {
  167. ViewState ["Text"] = value;
  168. if (HasControls ())
  169. Controls.Clear ();
  170. }
  171. }
  172. }
  173. }