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 string onclick = Attributes["onclick"];
193 if (onclick != null) {
194 Attributes.Remove("onclick");
195 int len = onclick.Length;
196 if (len > 0 && onclick[len - 1] != ';')
199 ClientScriptManager csm = new ClientScriptManager (Page);
200 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick + csm.GetClientValidationEvent ());
201 writer.AddAttribute ("language", "javascript");
204 base.AddAttributesToRender (writer);
209 protected virtual PostBackOptions GetPostBackOptions ()
211 throw new NotImplementedException ();
215 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
217 RaisePostBackEvent (eventArgument);
220 protected virtual void OnClick (EventArgs e)
222 if (Events != null) {
223 EventHandler eh = (EventHandler) (Events [ClickEvent]);
229 protected virtual void OnCommand (CommandEventArgs e)
231 if (Events != null) {
232 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
237 RaiseBubbleEvent (this, e);
243 void RaisePostBackEvent (string eventArgument)
245 if (CausesValidation)
247 Page.Validate (ValidationGroup);
252 OnClick (EventArgs.Empty);
253 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
261 override void RenderContents (HtmlTextWriter writer)
265 [WebSysDescription ("")]
266 [WebCategory ("Action")]
267 public event EventHandler Click
270 Events.AddHandler (ClickEvent, value);
273 Events.RemoveHandler (ClickEvent, value);
277 [WebSysDescription ("")]
278 [WebCategory ("Action")]
279 public event CommandEventHandler Command
282 Events.AddHandler (CommandEvent, value);
285 Events.RemoveHandler (CommandEvent, value);
291 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
293 [UrlProperty("*.aspx")]
295 public string PostBackUrl {
297 throw new NotImplementedException ();
300 throw new NotImplementedException ();
306 [WebSysDescription ("")]
307 [WebCategoryAttribute ("Behavior")]
308 public string ValidationGroup {
310 return ViewState.GetString ("ValidationGroup", "");
313 ViewState ["ValidationGroup"] = value;