2 // System.Web.UI.WebControls.LinkButton.cs
5 // Ben Maurer (bmaurer@novell.com)
7 // (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.WebControls {
35 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [ControlBuilder(typeof(LinkButtonControlBuilder))]
39 [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
40 [DefaultEvent("Click")]
41 [DefaultProperty("Text")]
42 [Designer("System.Web.UI.Design.WebControls.LinkButtonDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
43 [ParseChildren(false)]
45 [SupportsEventValidation]
46 [ToolboxData("<{0}:LinkButton runat=\"server\">LinkButton</{0}:LinkButton>")]
48 [ToolboxData("<{0}:LinkButton runat=server>LinkButton</{0}:LinkButton>")]
50 public class LinkButton : WebControl, IPostBackEventHandler
56 public LinkButton () : base (HtmlTextWriterTag.A)
61 protected override void AddAttributesToRender (HtmlTextWriter w)
64 Page.VerifyRenderingInServerForm (this);
66 base.AddAttributesToRender (w);
67 if (Page == null || !Enabled)
70 if (CausesValidation && Page.AreValidatorsUplevel ()) {
71 ClientScriptManager csm = new ClientScriptManager (Page);
72 w.AddAttribute (HtmlTextWriterAttribute.Href,
73 String.Format ("javascript:{{if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) {0};}}",
74 csm.GetPostBackEventReference (this, String.Empty)));
76 w.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, ""));
82 protected virtual void RaisePostBackEvent (string eventArgument)
84 throw new NotImplementedException ();
88 void IPostBackEventHandler.RaisePostBackEvent (string ea)
92 Page.Validate (ValidationGroup);
97 OnClick (EventArgs.Empty);
98 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
101 protected override void AddParsedSubObject (object obj)
103 if (HasControls ()) {
104 base.AddParsedSubObject (obj);
108 LiteralControl lc = obj as LiteralControl;
114 Controls.Add (new LiteralControl (s));
116 base.AddParsedSubObject (obj);
124 protected virtual PostBackOptions GetPostBackOptions ()
126 throw new NotImplementedException ();
130 protected override void LoadViewState (object savedState)
132 base.LoadViewState (savedState);
134 // Make sure we clear child controls when this happens
135 if (ViewState ["Text"] != null)
136 Text = (string) ViewState ["Text"];
139 [MonoTODO ("Why override?")]
145 override void OnPreRender (EventArgs e)
147 base.OnPreRender (e);
155 override void RenderContents (HtmlTextWriter writer)
158 base.RenderContents (writer);
168 [WebSysDescription ("")]
169 [WebCategory ("Behavior")]
176 bool CausesValidation {
178 return ViewState.GetBool ("CausesValidation", true);
181 ViewState ["CausesValidation"] = value;
188 [WebSysDescription ("")]
189 [WebCategory ("Behavior")]
193 public string CommandArgument {
195 return ViewState.GetString ("CommandArgument", "");
198 ViewState ["CommandArgument"] = value;
203 [WebSysDescription ("")]
204 [WebCategory ("Behavior")]
208 public string CommandName {
210 return ViewState.GetString ("CommandName", "");
214 ViewState ["CommandName"] = value;
223 [WebSysDescription ("")]
224 [WebCategoryAttribute ("Behavior")]
225 public virtual string OnClientClick
228 throw new NotImplementedException ();
231 throw new NotImplementedException ();
239 [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
243 [WebSysDescription ("")]
244 [WebCategory ("Appearance")]
245 public virtual string Text {
247 return ViewState.GetString ("Text", "");
250 ViewState ["Text"] = value;
256 protected virtual void OnClick (EventArgs e)
258 EventHandler h = (EventHandler) Events [ClickEvent];
262 static readonly object ClickEvent = new object ();
264 [WebSysDescription ("")]
265 [WebCategory ("Action")]
266 public event EventHandler Click {
267 add { Events.AddHandler (ClickEvent, value); }
268 remove { Events.RemoveHandler (ClickEvent, value); }
271 protected virtual void OnCommand (CommandEventArgs e)
273 CommandEventHandler h = (CommandEventHandler) Events [CommandEvent];
277 RaiseBubbleEvent (this, e);
279 static readonly object CommandEvent = new object ();
281 [WebSysDescription ("")]
282 [WebCategory ("Action")]
283 public event CommandEventHandler Command {
284 add { Events.AddHandler (CommandEvent, value); }
285 remove { Events.RemoveHandler (CommandEvent, value); }
288 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
290 [UrlProperty ("*.aspx")]
293 public virtual string PostBackUrl {
295 throw new NotImplementedException ();
298 throw new NotImplementedException ();
304 [WebSysDescription ("")]
305 [WebCategoryAttribute ("Behavior")]
306 public virtual string ValidationGroup {
308 return ViewState.GetString ("ValidationGroup", "");
311 ViewState ["ValidationGroup"] = value;