1 /* System.Web.UI.HtmlControls
3 * Leen Toelen (toelen@hotmail.com)
7 using System
.ComponentModel
;
11 namespace System
.Web
.UI
.HtmlControls
{
13 [DefaultEvent("ServerClick")]
14 public class HtmlAnchor
: HtmlContainerControl
, IPostBackEventHandler
{
16 private static readonly object EventServerClick
= new object ();
18 public HtmlAnchor(): base("a"){}
20 protected override void OnPreRender (EventArgs e
)
23 if (Page
!= null && Events
[EventServerClick
] != null)
24 Page
.RequiresPostBackScript ();
27 protected virtual void OnServerClick(EventArgs e
){
29 handler
= (EventHandler
) Events
[EventServerClick
];
34 protected override void RenderAttributes(HtmlTextWriter writer
){
35 if ( Events
[EventServerClick
] != null){
36 Attributes
.Remove("href");
37 base.RenderAttributes(writer
);
38 writer
.WriteAttribute("href", Page
.GetPostBackClientHyperlink(this,String
.Empty
));
41 PreProcessRelativeReference(writer
,"href");
42 base.RenderAttributes(writer
);
46 void System
.Web
.UI
.IPostBackEventHandler
.RaisePostBackEvent(string eventArgument
){
47 OnServerClick(EventArgs
.Empty
);
50 [WebCategory("Action")]
51 [WebSysDescription("Fires when the control is clicked.")]
52 public event EventHandler ServerClick
{
54 Events
.AddHandler(EventServerClick
, value);
57 Events
.RemoveHandler(EventServerClick
, value);
62 [WebCategory("Action")]
63 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
66 string attr
= Attributes
["href"];
67 if (attr
!= null) return attr
;
71 Attributes
["href"] = AttributeToString(value);
76 [WebCategory("Navigation")]
77 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
80 string attr
= Attributes
["name"];
81 if (attr
!= null) return attr
;
85 Attributes
["name"] = AttributeToString(value);
90 [WebCategory("Navigation")]
91 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
94 string attr
= Attributes
["target"];
95 if (attr
!= null) return attr
;
99 Attributes
["target"] = AttributeToString(value);
104 [WebCategory("Appearance")]
105 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
108 string attr
= Attributes
["title"];
109 if (attr
!= null) return attr
;
113 Attributes
["title"] = AttributeToString(value);
117 } // class HtmlAnchor
118 } // namespace System.Web.UI.HtmlControls