2 // System.Web.UI.HtmlControls.HtmlAnchor.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
30 using System.Security.Permissions;
32 namespace System.Web.UI.HtmlControls {
35 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [DefaultEvent ("ServerClick")]
40 [SupportsEventValidation]
42 public class HtmlAnchor : HtmlContainerControl, IPostBackEventHandler {
44 private static readonly object serverClickEvent = new object ();
53 [WebSysDescription("")]
54 [WebCategory("Action")]
55 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
61 string s = Attributes ["href"];
62 return (s == null) ? String.Empty : s;
66 Attributes.Remove ("href");
68 Attributes ["href"] = value;
74 [WebSysDescription("")]
75 [WebCategory("Navigation")]
76 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 string s = Attributes ["name"];
80 return (s == null) ? String.Empty : s;
84 Attributes.Remove ("name");
86 Attributes ["name"] = value;
91 [WebSysDescription("")]
92 [WebCategory("Navigation")]
93 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
94 public string Target {
96 string s = Attributes ["target"];
97 return (s == null) ? String.Empty : s;
101 Attributes.Remove ("target");
103 Attributes ["target"] = value;
108 [WebSysDescription("")]
109 [WebCategory("Appearance")]
110 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
114 public string Title {
116 string s = Attributes ["title"];
117 return (s == null) ? String.Empty : s;
121 Attributes.Remove ("title");
123 Attributes ["title"] = value;
132 override void OnPreRender (EventArgs e)
134 base.OnPreRender (e);
137 protected virtual void OnServerClick (EventArgs e)
139 EventHandler serverClick = (EventHandler) Events [serverClickEvent];
140 if (serverClick != null)
141 serverClick (this, e);
144 protected override void RenderAttributes (HtmlTextWriter writer)
146 // we don't want to render the "user" URL, so we either render:
148 EventHandler serverClick = (EventHandler) Events [serverClickEvent];
149 if (serverClick != null) {
151 ClientScriptManager csm = new ClientScriptManager (Page);
152 Attributes ["href"] = csm.GetPostBackClientHyperlink (this, String.Empty);
156 HRef = ResolveUrl (hr);
159 string target = Attributes ["target"];
160 if ((target == null) || (target.Length == 0))
161 Attributes.Remove("target");
163 base.RenderAttributes (writer);
165 // but we never set back the href attribute after the rendering
166 // nor is the property available after rendering
167 Attributes.Remove ("href");
170 protected virtual void RaisePostBackEvent (string eventArgument)
172 OnServerClick (EventArgs.Empty);
176 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
179 RaisePostBackEvent (eventArgument);
181 OnServerClick (EventArgs.Empty);
186 [WebSysDescription("")]
187 [WebCategory("Action")]
188 public event EventHandler ServerClick {
189 add { Events.AddHandler (serverClickEvent, value); }
190 remove { Events.RemoveHandler (serverClickEvent, value); }