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)));
75 w.AddAttribute ("language", "javascript");
77 w.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, ""));
83 protected virtual void RaisePostBackEvent (string eventArgument)
85 throw new NotImplementedException ();
89 void IPostBackEventHandler.RaisePostBackEvent (string ea)
93 Page.Validate (ValidationGroup);
98 OnClick (EventArgs.Empty);
99 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
102 protected override void AddParsedSubObject (object obj)
104 if (HasControls ()) {
105 base.AddParsedSubObject (obj);
109 LiteralControl lc = obj as LiteralControl;
115 Controls.Add (new LiteralControl (s));
117 base.AddParsedSubObject (obj);
125 protected virtual PostBackOptions GetPostBackOptions ()
127 throw new NotImplementedException ();
131 protected override void LoadViewState (object savedState)
133 base.LoadViewState (savedState);
135 // Make sure we clear child controls when this happens
136 if (ViewState ["Text"] != null)
137 Text = (string) ViewState ["Text"];
140 [MonoTODO ("Why override?")]
146 override void OnPreRender (EventArgs e)
148 base.OnPreRender (e);
156 override void RenderContents (HtmlTextWriter writer)
159 base.RenderContents (writer);
169 [WebSysDescription ("")]
170 [WebCategory ("Behavior")]
177 bool CausesValidation {
179 return ViewState.GetBool ("CausesValidation", true);
182 ViewState ["CausesValidation"] = value;
189 [WebSysDescription ("")]
190 [WebCategory ("Behavior")]
197 string CommandArgument {
199 return ViewState.GetString ("CommandArgument", "");
202 ViewState ["CommandArgument"] = value;
207 [WebSysDescription ("")]
208 [WebCategory ("Behavior")]
217 return ViewState.GetString ("CommandName", "");
221 ViewState ["CommandName"] = value;
230 [WebSysDescription ("")]
231 [WebCategoryAttribute ("Behavior")]
232 public virtual string OnClientClick
235 throw new NotImplementedException ();
238 throw new NotImplementedException ();
246 [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
250 [WebSysDescription ("")]
251 [WebCategory ("Appearance")]
252 public virtual string Text {
254 return ViewState.GetString ("Text", "");
257 ViewState ["Text"] = value;
263 protected virtual void OnClick (EventArgs e)
265 EventHandler h = (EventHandler) Events [ClickEvent];
269 static readonly object ClickEvent = new object ();
271 [WebSysDescription ("")]
272 [WebCategory ("Action")]
273 public event EventHandler Click {
274 add { Events.AddHandler (ClickEvent, value); }
275 remove { Events.RemoveHandler (ClickEvent, value); }
278 protected virtual void OnCommand (CommandEventArgs e)
280 CommandEventHandler h = (CommandEventHandler) Events [CommandEvent];
284 RaiseBubbleEvent (this, e);
286 static readonly object CommandEvent = new object ();
288 [WebSysDescription ("")]
289 [WebCategory ("Action")]
290 public event CommandEventHandler Command {
291 add { Events.AddHandler (CommandEvent, value); }
292 remove { Events.RemoveHandler (CommandEvent, value); }
295 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
297 [UrlProperty ("*.aspx")]
300 public string PostBackUrl {
302 throw new NotImplementedException ();
305 throw new NotImplementedException ();
311 [WebSysDescription ("")]
312 [WebCategoryAttribute ("Behavior")]
313 public string ValidationGroup {
315 return ViewState.GetString ("ValidationGroup", "");
318 ViewState ["ValidationGroup"] = value;