Button.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. //
  2. // System.Web.UI.WebControls.Button.cs
  3. //
  4. // Authors:
  5. // Jordi Mas i Hernandez ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using System.ComponentModel;
  29. using System.ComponentModel.Design;
  30. namespace System.Web.UI.WebControls {
  31. [DefaultEvent ("Click")]
  32. [DataBindingHandler ("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
  33. [DefaultProperty ("Text")]
  34. [Designer ("System.Web.UI.Design.WebControls.ButtonDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  35. [ToolboxDataAttribute ("<{0}:Button runat=server Text=\"Button\"></{0}:Button>")]
  36. public class Button : WebControl, IPostBackEventHandler
  37. #if NET_2_0
  38. , IButtonControl
  39. #endif
  40. {
  41. private static readonly object ClickEvent = new object ();
  42. private static readonly object CommandEvent = new object ();
  43. public Button () : base (HtmlTextWriterTag.Input)
  44. {
  45. }
  46. #if ONLY_1_1
  47. [Bindable (false)]
  48. #endif
  49. [WebSysDescription ("")]
  50. [WebCategory ("Behavior")]
  51. [DefaultValue (true)]
  52. #if NET_2_0
  53. [Themeable (false)]
  54. public virtual
  55. #else
  56. public
  57. #endif
  58. bool CausesValidation {
  59. get {
  60. return ViewState.GetBool ("CausesValidation", true);
  61. }
  62. set {
  63. ViewState ["CausesValidation"] = value;
  64. }
  65. }
  66. [DefaultValue ("")]
  67. [Bindable (true)]
  68. [WebSysDescription ("")]
  69. [WebCategory ("Behavior")]
  70. #if NET_2_0
  71. [Themeable (false)]
  72. public virtual
  73. #else
  74. public
  75. #endif
  76. string CommandArgument {
  77. get {
  78. return ViewState.GetString ("CommandArgument", "");
  79. }
  80. set {
  81. ViewState ["CommandArgument"] = value;
  82. }
  83. }
  84. [DefaultValue ("")]
  85. [WebSysDescription ("")]
  86. [WebCategory ("Behavior")]
  87. #if NET_2_0
  88. [Themeable (false)]
  89. public virtual
  90. #else
  91. public
  92. #endif
  93. string CommandName {
  94. get {
  95. return ViewState.GetString ("CommandName", "");
  96. }
  97. set {
  98. ViewState ["CommandName"] = value;
  99. }
  100. }
  101. #if NET_2_0
  102. [Themeable (false)]
  103. [DefaultValue ("")]
  104. [MonoTODO]
  105. [WebSysDescription ("")]
  106. [WebCategoryAttribute ("Behavior")]
  107. public virtual string OnClientClick
  108. {
  109. get {
  110. throw new NotImplementedException ();
  111. }
  112. set {
  113. throw new NotImplementedException ();
  114. }
  115. }
  116. #endif
  117. [DefaultValue ("")]
  118. [Bindable (true)]
  119. [WebSysDescription ("")]
  120. [WebCategory ("Appearance")]
  121. #if NET_2_0
  122. [Localizable (true)]
  123. public virtual
  124. #else
  125. public
  126. #endif
  127. string Text {
  128. get {
  129. return ViewState.GetString ("Text", "");
  130. }
  131. set {
  132. ViewState ["Text"] = value;
  133. }
  134. }
  135. #if NET_2_0
  136. [DefaultValue (true)]
  137. [Themeable (false)]
  138. [MonoTODO]
  139. [WebSysDescription ("")]
  140. [WebCategoryAttribute ("Behavior")]
  141. public virtual bool UseSubmitBehavior
  142. {
  143. get {
  144. throw new NotImplementedException ();
  145. }
  146. set {
  147. throw new NotImplementedException ();
  148. }
  149. }
  150. #endif
  151. protected override void AddAttributesToRender (HtmlTextWriter writer)
  152. {
  153. if (Page != null)
  154. Page.VerifyRenderingInServerForm (this);
  155. writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
  156. writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
  157. writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
  158. if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
  159. ClientScriptManager csm = new ClientScriptManager (Page);
  160. writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
  161. writer.AddAttribute ("language", "javascript");
  162. }
  163. base.AddAttributesToRender (writer);
  164. }
  165. #if NET_2_0
  166. [MonoTODO]
  167. protected virtual PostBackOptions GetPostBackOptions ()
  168. {
  169. throw new NotImplementedException ();
  170. }
  171. #endif
  172. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  173. {
  174. if (CausesValidation)
  175. #if NET_2_0
  176. Page.Validate (ValidationGroup);
  177. #else
  178. Page.Validate ();
  179. #endif
  180. OnClick (EventArgs.Empty);
  181. OnCommand (new CommandEventArgs (CommandName, CommandArgument));
  182. }
  183. protected virtual void OnClick (EventArgs e)
  184. {
  185. if (Events != null) {
  186. EventHandler eh = (EventHandler) (Events [ClickEvent]);
  187. if (eh != null)
  188. eh (this, e);
  189. }
  190. }
  191. protected virtual void OnCommand (CommandEventArgs e)
  192. {
  193. if (Events != null) {
  194. CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
  195. if (eh != null)
  196. eh (this, e);
  197. }
  198. RaiseBubbleEvent (this, e);
  199. }
  200. #if NET_2_0
  201. [MonoTODO]
  202. protected virtual void RaisePostBackEvent (string eventArgument)
  203. {
  204. throw new NotImplementedException ();
  205. }
  206. #endif
  207. [MonoTODO ("why is this here?")]
  208. #if NET_2_0
  209. protected internal
  210. #else
  211. protected
  212. #endif
  213. override void RenderContents (HtmlTextWriter writer)
  214. {
  215. base.RenderContents (writer);
  216. }
  217. [WebSysDescription ("")]
  218. [WebCategory ("Action")]
  219. public event EventHandler Click
  220. {
  221. add {
  222. Events.AddHandler (ClickEvent, value);
  223. }
  224. remove {
  225. Events.RemoveHandler (ClickEvent, value);
  226. }
  227. }
  228. [WebSysDescription ("")]
  229. [WebCategory ("Action")]
  230. public event CommandEventHandler Command
  231. {
  232. add {
  233. Events.AddHandler (CommandEvent, value);
  234. }
  235. remove {
  236. Events.RemoveHandler (CommandEvent, value);
  237. }
  238. }
  239. #if NET_2_0
  240. [DefaultValue ("")]
  241. [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  242. [Themeable (false)]
  243. [UrlProperty]
  244. [MonoTODO]
  245. public string PostBackUrl {
  246. get {
  247. throw new NotImplementedException ();
  248. }
  249. set {
  250. throw new NotImplementedException ();
  251. }
  252. }
  253. [DefaultValue ("")]
  254. [Themeable (false)]
  255. [WebSysDescription ("")]
  256. [WebCategoryAttribute ("Behavior")]
  257. public string ValidationGroup {
  258. get {
  259. return ViewState.GetString ("ValidationGroup", "");
  260. }
  261. set {
  262. ViewState ["ValidationGroup"] = value;
  263. }
  264. }
  265. #endif
  266. }
  267. }