HtmlAnchor.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, IPostBackEventHandler{
  10. private static readonly object EventServerClick;
  11. public HtmlAnchor(): base("a"){}
  12. protected virtual void OnServerClick(EventArgs e){
  13. EventHandler handler;
  14. handler = (EventHandler) Events[EventServerClick];
  15. if(handler != null) handler.Invoke(this, e);
  16. }
  17. protected new void RenderAttributes(HtmlTextWriter writer){
  18. if ( (EventHandler) Events[EventServerClick] != null){
  19. Attributes.Remove("href");
  20. RenderAttributes(writer);
  21. writer.WriteAttribute(Page.GetPostBackClientHyperlink(this,""),"href");
  22. }
  23. else{
  24. PreProcessRelativeReference(writer,"href");
  25. RenderAttributes(writer);
  26. }
  27. }
  28. public void RaisePostBackEvent(string eventArgument){
  29. OnServerClick(EventArgs.Empty);
  30. }
  31. public event EventHandler ServerClick{
  32. add{
  33. Events.AddHandler(EventServerClick, value);
  34. }
  35. remove{
  36. Events.RemoveHandler(EventServerClick, value);
  37. }
  38. }
  39. public string HRef{
  40. get{
  41. string attr = Attributes["href"];
  42. if (attr != null) return attr;
  43. return "";
  44. }
  45. set{
  46. Attributes["href"] = AttributeToString(value);
  47. }
  48. }
  49. public string Name{
  50. get{
  51. string attr = Attributes["name"];
  52. if (attr != null) return attr;
  53. return "";
  54. }
  55. set{
  56. Attributes["name"] = AttributeToString(value);
  57. }
  58. }
  59. public string Target{
  60. get{
  61. string attr = Attributes["target"];
  62. if (attr != null) return attr;
  63. return "";
  64. }
  65. set{
  66. Attributes["target"] = AttributeToString(value);
  67. }
  68. }
  69. public string Title{
  70. get{
  71. string attr = Attributes["title"];
  72. if (attr != null) return attr;
  73. return "";
  74. }
  75. set{
  76. Attributes["title"] = AttributeToString(value);
  77. }
  78. }
  79. } // class HtmlAnchor
  80. } // namespace System.Web.UI.HtmlControls