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;
32 namespace System.Web.UI.WebControls {
34 [DefaultEvent ("Click")]
35 [DataBindingHandler ("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
36 [DefaultProperty ("Text")]
37 [Designer ("System.Web.UI.Design.WebControls.ButtonDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
40 [ToolboxDataAttribute ("<{0}:Button runat=\"server\" Text=\"Button\"></{0}:Button>")]
42 [ToolboxDataAttribute ("<{0}:Button runat=server Text=\"Button\"></{0}:Button>")]
45 public class Button : WebControl, IPostBackEventHandler
51 private static readonly object ClickEvent = new object ();
52 private static readonly object CommandEvent = new object ();
54 public Button () : base (HtmlTextWriterTag.Input)
61 [WebSysDescription ("")]
62 [WebCategory ("Behavior")]
70 bool CausesValidation {
72 return ViewState.GetBool ("CausesValidation", true);
76 ViewState ["CausesValidation"] = value;
82 [WebSysDescription ("")]
83 [WebCategory ("Behavior")]
90 string CommandArgument {
92 return ViewState.GetString ("CommandArgument", "");
95 ViewState ["CommandArgument"] = value;
100 [WebSysDescription ("")]
101 [WebCategory ("Behavior")]
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")]
147 return ViewState.GetString ("Text", "");
150 ViewState ["Text"] = value;
155 [DefaultValue (true)]
158 [WebSysDescription ("")]
159 [WebCategoryAttribute ("Behavior")]
160 public virtual bool UseSubmitBehavior
163 throw new NotImplementedException ();
166 throw new NotImplementedException ();
171 protected override void AddAttributesToRender (HtmlTextWriter writer)
174 Page.VerifyRenderingInServerForm (this);
176 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
177 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
178 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
180 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
181 ClientScriptManager csm = new ClientScriptManager (Page);
182 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
183 writer.AddAttribute ("language", "javascript");
186 base.AddAttributesToRender (writer);
191 protected virtual PostBackOptions GetPostBackOptions ()
193 throw new NotImplementedException ();
197 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
199 RaisePostBackEvent (eventArgument);
202 protected virtual void OnClick (EventArgs e)
204 if (Events != null) {
205 EventHandler eh = (EventHandler) (Events [ClickEvent]);
211 protected virtual void OnCommand (CommandEventArgs e)
213 if (Events != null) {
214 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
219 RaiseBubbleEvent (this, e);
225 void RaisePostBackEvent (string eventArgument)
227 if (CausesValidation)
229 Page.Validate (ValidationGroup);
234 OnClick (EventArgs.Empty);
235 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
243 override void RenderContents (HtmlTextWriter writer)
247 [WebSysDescription ("")]
248 [WebCategory ("Action")]
249 public event EventHandler Click
252 Events.AddHandler (ClickEvent, value);
255 Events.RemoveHandler (ClickEvent, value);
259 [WebSysDescription ("")]
260 [WebCategory ("Action")]
261 public event CommandEventHandler Command
264 Events.AddHandler (CommandEvent, value);
267 Events.RemoveHandler (CommandEvent, value);
273 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
275 [UrlProperty("*.aspx")]
277 public string PostBackUrl {
279 throw new NotImplementedException ();
282 throw new NotImplementedException ();
288 [WebSysDescription ("")]
289 [WebCategoryAttribute ("Behavior")]
290 public string ValidationGroup {
292 return ViewState.GetString ("ValidationGroup", "");
295 ViewState ["ValidationGroup"] = value;