Move negative tests from ilasm/tests to ilasm/errors.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Button.cs
1 //
2 // System.Web.UI.WebControls.Button.cs
3 //
4 // Authors:
5 //      Jordi Mas i Hernandez (jordi@ximian.com)
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
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
31 using System.Security.Permissions;
32
33 namespace System.Web.UI.WebControls {
34
35         // CAS
36         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38         // attributes
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")]
43
44 #if NET_2_0
45         [ToolboxDataAttribute ("<{0}:Button runat=\"server\" Text=\"Button\"></{0}:Button>")]
46         [SupportsEventValidation]
47 #else
48         [ToolboxDataAttribute ("<{0}:Button runat=server Text=\"Button\"></{0}:Button>")]
49 #endif
50
51         public class Button : WebControl, IPostBackEventHandler
52 #if NET_2_0
53         , IButtonControl
54 #endif
55         {
56
57                 private static readonly object ClickEvent = new object ();
58                 private static readonly object CommandEvent = new object ();
59
60                 public Button () : base (HtmlTextWriterTag.Input)
61                 {
62                 }
63
64 #if ONLY_1_1
65                 [Bindable (false)]
66 #endif          
67                 [WebSysDescription ("")]
68                 [WebCategory ("Behavior")]
69                 [DefaultValue (true)]
70 #if NET_2_0
71                 [Themeable (false)]
72                 public virtual
73 #else           
74                 public
75 #endif          
76                 bool CausesValidation {
77                         get {
78                                 return ViewState.GetBool ("CausesValidation", true);
79                         }
80
81                         set {
82                                 ViewState ["CausesValidation"] = value;
83                         }
84                 }
85
86                 [DefaultValue ("")]
87                 [Bindable (true)]
88                 [WebSysDescription ("")]
89                 [WebCategory ("Behavior")]
90 #if NET_2_0
91                 [Themeable (false)]
92                 public virtual
93 #else           
94                 public
95 #endif          
96                 string CommandArgument {
97                         get {
98                                 return ViewState.GetString ("CommandArgument", "");
99                         }
100                         set {
101                                 ViewState ["CommandArgument"] = value;
102                         }
103                 }
104
105                 [DefaultValue ("")]
106                 [WebSysDescription ("")]
107                 [WebCategory ("Behavior")]
108 #if NET_2_0
109                 [Themeable (false)]
110                 public virtual
111 #else
112                 public
113 #endif          
114                 string CommandName {
115                         get {
116                                 return ViewState.GetString ("CommandName", "");
117                         }
118                         set {
119                                 ViewState ["CommandName"] = value;
120                         }
121                 }
122
123 #if NET_2_0
124                 [Themeable (false)]
125                 [DefaultValue ("")]
126                 [MonoTODO]
127                 [WebSysDescription ("")]
128                 [WebCategoryAttribute ("Behavior")]
129                 public virtual string OnClientClick 
130                 {
131                         get {
132                                 throw new NotImplementedException ();
133                         }
134                         set {
135                                 throw new NotImplementedException ();
136                         }
137                 }
138
139 #endif          
140
141                 [DefaultValue ("")]
142                 [Bindable (true)]
143                 [WebSysDescription ("")]
144                 [WebCategory ("Appearance")]
145 #if NET_2_0
146                 [Localizable (true)]
147                 public virtual
148 #else           
149                 public
150 #endif          
151                 string Text {
152                         get {
153                                 return ViewState.GetString ("Text", "");
154                         }
155                         set {
156                                 ViewState ["Text"] = value;
157                         }
158                 }
159
160 #if NET_2_0
161                 [DefaultValue (true)]
162                 [Themeable (false)]
163                 [MonoTODO]
164                 [WebSysDescription ("")]
165                 [WebCategoryAttribute ("Behavior")]
166                 public virtual bool UseSubmitBehavior 
167                 {
168                         get {
169                                 throw new NotImplementedException ();
170                         }
171                         set {
172                                 throw new NotImplementedException ();
173                         }
174                 }
175 #endif          
176
177                 protected override void AddAttributesToRender (HtmlTextWriter writer)
178                 {
179                         if (Page != null)
180                                 Page.VerifyRenderingInServerForm (this);
181
182                         writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
183 #if NET_2_0
184                         if (ID != null)
185                                 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
186 #else
187                         writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
188 #endif
189                         writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
190
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] != ';')
197                                                 onclick += ";";
198                                 }
199                                 ClientScriptManager csm = new ClientScriptManager (Page);
200                                 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick + csm.GetClientValidationEvent ());
201                                 writer.AddAttribute ("language", "javascript");
202                         }
203
204                         base.AddAttributesToRender (writer);
205                 }
206
207 #if NET_2_0
208                 [MonoTODO]
209                 protected virtual PostBackOptions GetPostBackOptions ()
210                 {
211                         throw new NotImplementedException ();
212                 }
213 #endif          
214
215                 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
216                 {
217                         RaisePostBackEvent (eventArgument);
218                 }
219
220                 protected virtual void OnClick (EventArgs e)
221                 {
222                         if (Events != null) {
223                                 EventHandler eh = (EventHandler) (Events [ClickEvent]);
224                                 if (eh != null)
225                                         eh (this, e);
226                         }
227                 }
228
229                 protected virtual void OnCommand (CommandEventArgs e)
230                 {
231                         if (Events != null) {
232                                 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
233                                 if (eh != null)
234                                         eh (this, e);
235                         }
236
237                         RaiseBubbleEvent (this, e);
238                 }
239
240 #if NET_2_0
241                 protected virtual
242 #endif
243                 void RaisePostBackEvent (string eventArgument)
244                 {
245                         if (CausesValidation)
246 #if NET_2_0
247                                 Page.Validate (ValidationGroup);
248 #else
249                                 Page.Validate ();
250 #endif
251
252                         OnClick (EventArgs.Empty);
253                         OnCommand (new CommandEventArgs (CommandName, CommandArgument));
254                 }
255
256 #if NET_2_0
257                 protected internal
258 #else           
259                 protected
260 #endif          
261                 override void RenderContents (HtmlTextWriter writer)
262                 {
263                 }
264
265                 [WebSysDescription ("")]
266                 [WebCategory ("Action")]
267                 public event EventHandler Click
268                 {
269                         add {
270                                 Events.AddHandler (ClickEvent, value);
271                         }
272                         remove {
273                                 Events.RemoveHandler (ClickEvent, value);
274                         }
275                 }
276
277                 [WebSysDescription ("")]
278                 [WebCategory ("Action")]
279                 public event CommandEventHandler Command
280                 {
281                         add {
282                                 Events.AddHandler (CommandEvent, value);
283                         }
284                         remove {
285                                 Events.RemoveHandler (CommandEvent, value);
286                         }
287                 }
288
289 #if NET_2_0
290                 [DefaultValue ("")]
291                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
292                 [Themeable (false)]
293                 [UrlProperty("*.aspx")]
294                 [MonoTODO]
295                 public string PostBackUrl {
296                         get {
297                                 throw new NotImplementedException ();
298                         }
299                         set {
300                                 throw new NotImplementedException ();
301                         }
302                 }
303
304                 [DefaultValue ("")]
305                 [Themeable (false)]
306                 [WebSysDescription ("")]
307                 [WebCategoryAttribute ("Behavior")]
308                 public string ValidationGroup {
309                         get {
310                                 return ViewState.GetString ("ValidationGroup", "");
311                         }
312                         set {
313                                 ViewState ["ValidationGroup"] = value;
314                         }
315                 }       
316 #endif
317
318         }
319 }
320