HtmlAnchor.cs 2.2 KB

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