2 // System.Web.UI.WebControls.Button.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.ComponentModel;
14 using System.ComponentModel.Design;
18 namespace System.Web.UI.WebControls
20 [DefaultEvent("Click")]
21 [DefaultProperty("Text")]
22 [Designer("System.Web.UI.Design.WebControls.ButtonDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
\r
23 [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
24 [ToolboxData("<{0}:Button runat=\"server\" Text=\"Button\"></{0}:Button>")]
25 public class Button : WebControl, IPostBackEventHandler
27 private static readonly object ClickEvent = new object();
28 private static readonly object CommandEvent = new object();
30 //private EventHandlerList ehList;
32 public Button(): base (HtmlTextWriterTag.Input)
36 [DefaultValue (true), Bindable (false), WebCategory ("Behavior")]
37 [WebSysDescription ("Determines if validation is performed when clicked.")]
38 public bool CausesValidation
42 Object cv = ViewState["CausesValidation"];
49 ViewState["CausesValidation"] = value;
53 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
54 [WebSysDescription ("An argument for the Command of this control.")]
55 public string CommandArgument
59 string ca = (string) ViewState["CommandArgument"];
66 ViewState["CommandArgument"] = value;
70 [DefaultValue (""), WebCategory ("Behavior")]
71 [WebSysDescription ("The name of the Command of this control.")]
72 public string CommandName
76 string cn = (string)ViewState["CommandName"];
83 ViewState["CommandName"] = value;
87 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
88 [WebSysDescription ("The text that should be shown on this Button.")]
93 string text = (string)ViewState["Text"];
100 ViewState["Text"] = value;
104 [WebCategory ("Action")]
105 [WebSysDescription ("Raised when the Button is clicked.")]
106 public event EventHandler Click
110 Events.AddHandler(ClickEvent, value);
114 Events.RemoveHandler(ClickEvent, value);
118 [WebCategory ("Action")]
119 [WebSysDescription ("Raised when a Button Command is executed.")]
120 public event CommandEventHandler Command
124 Events.AddHandler(CommandEvent, value);
128 Events.RemoveHandler(CommandEvent, value);
132 protected virtual void OnClick(EventArgs e)
136 EventHandler eh = (EventHandler)(Events[ClickEvent]);
142 protected virtual void OnCommand(CommandEventArgs e)
146 CommandEventHandler eh = (CommandEventHandler)(Events[CommandEvent]);
150 RaiseBubbleEvent(this, e);
153 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
155 if (CausesValidation)
158 OnClick (EventArgs.Empty);
159 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
162 protected override void AddAttributesToRender (HtmlTextWriter writer)
165 Page.VerifyRenderingInServerForm (this);
167 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
168 writer.AddAttribute (HtmlTextWriterAttribute.Name, base.UniqueID);
169 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
170 if (Page != null && CausesValidation && Page.Validators.Count > 0) {
171 writer.AddAttribute (System.Web.UI.HtmlTextWriterAttribute.Onclick,
172 Utils.GetClientValidatedEvent (Page));
173 writer.AddAttribute ("language", "javascript");
175 base.AddAttributesToRender (writer);
178 protected override void RenderContents(HtmlTextWriter writer)
180 // Preventing base classes to do anything