2 // System.Web.UI.WebControls.Button.cs
5 // Jordi Mas i Hernandez (jordi@ximian.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.ComponentModel.Design;
31 using System.Security.Permissions;
33 namespace System.Web.UI.WebControls {
36 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [DefaultEvent ("Click")]
40 [DataBindingHandler ("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
41 [DefaultProperty ("Text")]
42 [Designer ("System.Web.UI.Design.WebControls.ButtonDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45 [ToolboxDataAttribute ("<{0}:Button runat=\"server\" Text=\"Button\"></{0}:Button>")]
46 [SupportsEventValidation]
48 [ToolboxDataAttribute ("<{0}:Button runat=server Text=\"Button\"></{0}:Button>")]
51 public class Button : WebControl, IPostBackEventHandler
57 private static readonly object ClickEvent = new object ();
58 private static readonly object CommandEvent = new object ();
60 public Button () : base (HtmlTextWriterTag.Input)
67 [WebSysDescription ("")]
68 [WebCategory ("Behavior")]
76 bool CausesValidation {
78 return ViewState.GetBool ("CausesValidation", true);
82 ViewState ["CausesValidation"] = value;
88 [WebSysDescription ("")]
89 [WebCategory ("Behavior")]
96 string CommandArgument {
98 return ViewState.GetString ("CommandArgument", "");
101 ViewState ["CommandArgument"] = value;
106 [WebSysDescription ("")]
107 [WebCategory ("Behavior")]
116 return ViewState.GetString ("CommandName", "");
119 ViewState ["CommandName"] = value;
127 [WebSysDescription ("")]
128 [WebCategoryAttribute ("Behavior")]
129 public virtual string OnClientClick
132 throw new NotImplementedException ();
135 throw new NotImplementedException ();
143 [WebSysDescription ("")]
144 [WebCategory ("Appearance")]
153 return ViewState.GetString ("Text", "");
156 ViewState ["Text"] = value;
161 [DefaultValue (true)]
164 [WebSysDescription ("")]
165 [WebCategoryAttribute ("Behavior")]
166 public virtual bool UseSubmitBehavior
169 throw new NotImplementedException ();
172 throw new NotImplementedException ();
177 protected override void AddAttributesToRender (HtmlTextWriter writer)
180 Page.VerifyRenderingInServerForm (this);
182 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
185 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
187 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
189 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
191 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
192 ClientScriptManager csm = new ClientScriptManager (Page);
193 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
194 writer.AddAttribute ("language", "javascript");
197 base.AddAttributesToRender (writer);
202 protected virtual PostBackOptions GetPostBackOptions ()
204 throw new NotImplementedException ();
208 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
210 RaisePostBackEvent (eventArgument);
213 protected virtual void OnClick (EventArgs e)
215 if (Events != null) {
216 EventHandler eh = (EventHandler) (Events [ClickEvent]);
222 protected virtual void OnCommand (CommandEventArgs e)
224 if (Events != null) {
225 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
230 RaiseBubbleEvent (this, e);
236 void RaisePostBackEvent (string eventArgument)
238 if (CausesValidation)
240 Page.Validate (ValidationGroup);
245 OnClick (EventArgs.Empty);
246 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
254 override void RenderContents (HtmlTextWriter writer)
258 [WebSysDescription ("")]
259 [WebCategory ("Action")]
260 public event EventHandler Click
263 Events.AddHandler (ClickEvent, value);
266 Events.RemoveHandler (ClickEvent, value);
270 [WebSysDescription ("")]
271 [WebCategory ("Action")]
272 public event CommandEventHandler Command
275 Events.AddHandler (CommandEvent, value);
278 Events.RemoveHandler (CommandEvent, value);
284 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
286 [UrlProperty("*.aspx")]
288 public string PostBackUrl {
290 throw new NotImplementedException ();
293 throw new NotImplementedException ();
299 [WebSysDescription ("")]
300 [WebCategoryAttribute ("Behavior")]
301 public string ValidationGroup {
303 return ViewState.GetString ("ValidationGroup", "");
306 ViewState ["ValidationGroup"] = value;