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")]
93 public string CommandArgument {
95 return ViewState.GetString ("CommandArgument", "");
98 ViewState ["CommandArgument"] = value;
103 [WebSysDescription ("")]
104 [WebCategory ("Behavior")]
108 public string CommandName {
110 return ViewState.GetString ("CommandName", "");
113 ViewState ["CommandName"] = value;
121 [WebSysDescription ("")]
122 [WebCategoryAttribute ("Behavior")]
123 public virtual string OnClientClick
126 throw new NotImplementedException ();
129 throw new NotImplementedException ();
137 [WebSysDescription ("")]
138 [WebCategory ("Appearance")]
144 return ViewState.GetString ("Text", "");
147 ViewState ["Text"] = value;
152 [DefaultValue (true)]
155 [WebSysDescription ("")]
156 [WebCategoryAttribute ("Behavior")]
157 public virtual bool UseSubmitBehavior
160 throw new NotImplementedException ();
163 throw new NotImplementedException ();
168 protected override void AddAttributesToRender (HtmlTextWriter writer)
171 Page.VerifyRenderingInServerForm (this);
173 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
176 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
178 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
180 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
182 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
183 string onclick = Attributes["onclick"];
184 if (onclick != null) {
185 Attributes.Remove("onclick");
186 int len = onclick.Length;
187 if (len > 0 && onclick[len - 1] != ';')
190 ClientScriptManager csm = new ClientScriptManager (Page);
191 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick + csm.GetClientValidationEvent ());
192 writer.AddAttribute ("language", "javascript");
195 base.AddAttributesToRender (writer);
200 protected virtual PostBackOptions GetPostBackOptions ()
202 throw new NotImplementedException ();
206 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
208 RaisePostBackEvent (eventArgument);
211 protected virtual void OnClick (EventArgs e)
213 if (Events != null) {
214 EventHandler eh = (EventHandler) (Events [ClickEvent]);
220 protected virtual void OnCommand (CommandEventArgs e)
222 if (Events != null) {
223 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
228 RaiseBubbleEvent (this, e);
234 void RaisePostBackEvent (string eventArgument)
236 if (CausesValidation)
238 Page.Validate (ValidationGroup);
243 OnClick (EventArgs.Empty);
244 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
252 override void RenderContents (HtmlTextWriter writer)
256 [WebSysDescription ("")]
257 [WebCategory ("Action")]
258 public event EventHandler Click
261 Events.AddHandler (ClickEvent, value);
264 Events.RemoveHandler (ClickEvent, value);
268 [WebSysDescription ("")]
269 [WebCategory ("Action")]
270 public event CommandEventHandler Command
273 Events.AddHandler (CommandEvent, value);
276 Events.RemoveHandler (CommandEvent, value);
282 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
284 [UrlProperty("*.aspx")]
286 public virtual string PostBackUrl {
288 return ViewState.GetString ("PostBackUrl", "");
291 ViewState ["PostBackUrl"] = value;
297 [WebSysDescription ("")]
298 [WebCategoryAttribute ("Behavior")]
299 public virtual string ValidationGroup {
301 return ViewState.GetString ("ValidationGroup", "");
304 ViewState ["ValidationGroup"] = value;