HtmlAnchor.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.ComponentModel;
  7. using System.Web;
  8. using System.Web.UI;
  9. namespace System.Web.UI.HtmlControls{
  10. [DefaultEvent("ServerClick")]
  11. public class HtmlAnchor : HtmlContainerControl, IPostBackEventHandler{
  12. private static readonly object EventServerClick = new object ();
  13. public HtmlAnchor(): base("a"){}
  14. protected override void OnPreRender (EventArgs e)
  15. {
  16. base.OnPreRender (e);
  17. if (Page != null && Events [EventServerClick] != null)
  18. Page.RequiresPostBackScript ();
  19. }
  20. protected virtual void OnServerClick(EventArgs e){
  21. EventHandler handler;
  22. handler = (EventHandler) Events[EventServerClick];
  23. if (handler != null)
  24. handler (this, e);
  25. }
  26. protected override void RenderAttributes(HtmlTextWriter writer){
  27. if ( Events[EventServerClick] != null){
  28. Attributes.Remove("href");
  29. base.RenderAttributes(writer);
  30. writer.WriteAttribute("href", Page.GetPostBackClientHyperlink(this,String.Empty));
  31. }
  32. else{
  33. PreProcessRelativeReference(writer,"href");
  34. base.RenderAttributes(writer);
  35. }
  36. }
  37. void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(string eventArgument){
  38. OnServerClick(EventArgs.Empty);
  39. }
  40. [WebCategory("Action")]
  41. [WebSysDescription("Fires when the control is clicked.")]
  42. public event EventHandler ServerClick{
  43. add{
  44. Events.AddHandler(EventServerClick, value);
  45. }
  46. remove{
  47. Events.RemoveHandler(EventServerClick, value);
  48. }
  49. }
  50. [DefaultValue("")]
  51. [WebCategory("Action")]
  52. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  53. public string HRef{
  54. get{
  55. string attr = Attributes["href"];
  56. if (attr != null) return attr;
  57. return String.Empty;
  58. }
  59. set{
  60. Attributes["href"] = AttributeToString(value);
  61. }
  62. }
  63. [DefaultValue("")]
  64. [WebCategory("Navigation")]
  65. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  66. public string Name{
  67. get{
  68. string attr = Attributes["name"];
  69. if (attr != null) return attr;
  70. return String.Empty;
  71. }
  72. set{
  73. Attributes["name"] = AttributeToString(value);
  74. }
  75. }
  76. [DefaultValue("")]
  77. [WebCategory("Navigation")]
  78. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  79. public string Target{
  80. get{
  81. string attr = Attributes["target"];
  82. if (attr != null) return attr;
  83. return String.Empty;
  84. }
  85. set{
  86. Attributes["target"] = AttributeToString(value);
  87. }
  88. }
  89. [DefaultValue("")]
  90. [WebCategory("Appearance")]
  91. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  92. public string Title{
  93. get{
  94. string attr = Attributes["title"];
  95. if (attr != null) return attr;
  96. return String.Empty;
  97. }
  98. set{
  99. Attributes["title"] = AttributeToString(value);
  100. }
  101. }
  102. } // class HtmlAnchor
  103. } // namespace System.Web.UI.HtmlControls