HtmlAnchor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* System.Web.Configuration
  2. * Authors:
  3. * Leen Toelen ([email protected])
  4. * Copyright (C) 2001 Leen Toelen
  5. */
  6. using System;
  7. using System.Web;
  8. using System.Web.UI;
  9. namespace System.Web.UI.HtmlControls{
  10. public class HtmlAnchor : HtmlContainerControl, IPostBackDataHandler{
  11. private static object EventServerClick = new Object();
  12. public HtmlAnchor(): base("a"){}
  13. protected virtual void OnServerClick(EventArgs e){
  14. EventHandler handler;
  15. handler = (EventHandler) Events[EventServerClick];
  16. if(handler != null){
  17. handler.Invoke(this, e);
  18. }
  19. }
  20. protected override void RenderAttributes(HtmlTextWriter writer){
  21. if ((EventHandler) Events[EventServerClick] != null){
  22. Attributes.Remove("href");
  23. RenderAttributes(writer);
  24. writer.WriteAttribute(Page.GetPostBackClientHyperlink(this,""),"href");
  25. }
  26. else{
  27. PreProcessRelativeReferenceAttribute(writer,"href");
  28. RenderAttributes(writer);
  29. }
  30. }
  31. //FIXME: not sure about the accessor
  32. public void RaisePostBackEvent(string eventArgument){
  33. OnServerClick(EventArgs.Empty);
  34. }
  35. public event EventHandler ServerClick{
  36. add{
  37. Events.AddHandler(EventServerClick, value);
  38. }
  39. remove{
  40. Events.RemoveHandler(EventServerClick, value);
  41. }
  42. }
  43. public int HRef{
  44. get{
  45. string attr = Attributes["href"];
  46. if (attr != null){
  47. return attr;
  48. }
  49. return "";
  50. }
  51. set{
  52. //MapIntegerAttributeToString(value) accessible constraint is "assembly"
  53. Attributes["href"] = MapIntegerAttributeToString(value);
  54. }
  55. }
  56. public string Name{
  57. get{
  58. string attr = Attributes["name"];
  59. if (attr != null){
  60. return attr;
  61. }
  62. return "";
  63. }
  64. set{
  65. Attributes["name"] = MapStringAttributeToString(value);
  66. }
  67. }
  68. public string Target{
  69. get{
  70. string attr = Attributes["target"];
  71. if (attr != null){
  72. return attr;
  73. }
  74. return "";
  75. }
  76. set{
  77. Attributes["target"] = MapStringAttributeToString(value);
  78. }
  79. }
  80. public string Title{
  81. get{
  82. string attr = Attributes["title"];
  83. if (attr != null){
  84. return attr;
  85. }
  86. return "";
  87. }
  88. set{
  89. Attributes["title"] = MapStringAttributeToString(value);
  90. }
  91. }
  92. } // class HtmlAnchor
  93. } // namespace System.Web.UI.HtmlControls