2 // System.Web.UI.WebControls.ImageButton.cs
5 // Jordi Mas i Hernandez (jordi@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Specialized;
32 using System.ComponentModel;
33 using System.Security.Permissions;
35 namespace System.Web.UI.WebControls {
38 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 [DefaultEvent("Click")]
43 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
44 [SupportsEventValidation]
45 public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler, IButtonControl {
47 public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler {
49 private static readonly object ClickEvent = new object ();
50 private static readonly object CommandEvent = new object ();
51 private int pos_x, pos_y;
62 [WebSysDescription ("")]
63 [WebCategory ("Behavior")]
70 bool CausesValidation {
72 return ViewState.GetBool ("CausesValidation", true);
76 ViewState ["CausesValidation"] = value;
82 [WebSysDescription ("")]
83 [WebCategory ("Behavior")]
87 public string CommandArgument {
89 return ViewState.GetString ("CommandArgument", "");
92 ViewState ["CommandArgument"] = value;
97 [WebSysDescription ("")]
98 [WebCategory ("Behavior")]
102 public string CommandName {
104 return ViewState.GetString ("CommandName", "");
107 ViewState ["CommandName"] = value;
112 [EditorBrowsable (EditorBrowsableState.Always)]
114 [DefaultValue (true)]
117 public virtual new bool Enabled
120 throw new NotImplementedException ();
123 throw new NotImplementedException ();
128 [EditorBrowsable (EditorBrowsableState.Never)]
130 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
132 public virtual new bool GenerateEmptyAlternateText
135 throw new NotImplementedException ();
138 throw new NotImplementedException ();
145 public virtual string OnClientClick
148 throw new NotImplementedException ();
151 throw new NotImplementedException ();
157 [UrlProperty ("*.aspx")]
162 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
164 public virtual string PostBackUrl
167 throw new NotImplementedException ();
170 throw new NotImplementedException ();
176 [WebSysDescription ("")]
177 [WebCategory ("Behavior")]
178 public virtual string ValidationGroup
181 return ViewState.GetString ("ValidationGroup", "");
184 ViewState ["ValidationGroup"] = value;
190 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
191 #if NET_2_0 && HAVE_CONTROL_ADAPTERS
192 protected virtual new
196 HtmlTextWriterTag TagKey {
197 get { return HtmlTextWriterTag.Input; }
202 protected virtual string Text
205 throw new NotImplementedException ();
208 throw new NotImplementedException ();
213 protected override void AddAttributesToRender (HtmlTextWriter writer)
216 Page.VerifyRenderingInServerForm (this);
218 writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
219 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
220 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
221 ClientScriptManager csm = new ClientScriptManager (Page);
222 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
223 writer.AddAttribute ("language", "javascript");
225 base.AddAttributesToRender (writer);
230 protected virtual PostBackOptions GetPostBackOptions ()
232 throw new NotImplementedException ();
240 bool LoadPostData (string postDataKey, NameValueCollection postCollection)
243 string unique = UniqueID;
244 x = postCollection [unique + ".x"];
245 y = postCollection [unique + ".y"];
246 if (x != null && x != "" && y != null && y != "") {
247 pos_x = Int32.Parse(x);
248 pos_y = Int32.Parse(y);
249 Page.RegisterRequiresRaiseEvent (this);
252 x = postCollection [unique];
253 if (x != null && x != "") {
254 pos_x = Int32.Parse (x);
256 Page.RegisterRequiresRaiseEvent (this);
266 void RaisePostDataChangedEvent ()
268 if (CausesValidation)
270 Page.Validate (ValidationGroup);
275 OnClick (new ImageClickEventArgs (pos_x, pos_y));
276 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
283 void RaisePostBackEvent (string eventArgument)
287 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
289 return LoadPostData (postDataKey, postCollection);
293 void IPostBackDataHandler.RaisePostDataChangedEvent ()
295 RaisePostDataChangedEvent ();
298 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
300 RaisePostBackEvent (eventArgument);
303 protected virtual void OnClick (ImageClickEventArgs e)
305 if (Events != null) {
306 ImageClickEventHandler eh = (ImageClickEventHandler) (Events [ClickEvent]);
312 protected virtual void OnCommand (CommandEventArgs e)
314 if (Events != null) {
315 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
320 RaiseBubbleEvent (this, e);
328 override void OnPreRender (EventArgs e)
331 Page.RegisterRequiresPostBack (this);
334 [WebSysDescription ("")]
335 [WebCategory ("Action")]
336 public event ImageClickEventHandler Click
339 Events.AddHandler (ClickEvent, value);
342 Events.RemoveHandler (ClickEvent, value);
346 [WebSysDescription ("")]
347 [WebCategory ("Action")]
348 public event CommandEventHandler Command
351 Events.AddHandler (CommandEvent, value);
354 Events.RemoveHandler (CommandEvent, value);
360 string IButtonControl.Text
363 throw new NotImplementedException ();
366 throw new NotImplementedException ();
371 event EventHandler IButtonControl.Click
374 throw new NotImplementedException ();
377 throw new NotImplementedException ();