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;
34 namespace System.Web.UI.WebControls {
35 [DefaultEvent("Click")]
37 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
39 public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler
45 private static readonly object ClickEvent = new object ();
46 private static readonly object CommandEvent = new object ();
47 private int pos_x, pos_y;
58 [WebSysDescription ("")]
59 [WebCategory ("Behavior")]
66 bool CausesValidation {
68 return ViewState.GetBool ("CausesValidation", true);
72 ViewState ["CausesValidation"] = value;
78 [WebSysDescription ("")]
79 [WebCategory ("Behavior")]
86 string CommandArgument {
88 return ViewState.GetString ("CommandArgument", "");
91 ViewState ["CommandArgument"] = value;
96 [WebSysDescription ("")]
97 [WebCategory ("Behavior")]
106 return ViewState.GetString ("CommandName", "");
109 ViewState ["CommandName"] = value;
114 [EditorBrowsable (EditorBrowsableState.Always)]
116 [DefaultValue (true)]
119 public virtual new bool Enabled
122 throw new NotImplementedException ();
125 throw new NotImplementedException ();
130 [EditorBrowsable (EditorBrowsableState.Never)]
132 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
134 public virtual new bool GenerateEmptyAlternateText
137 throw new NotImplementedException ();
140 throw new NotImplementedException ();
147 public virtual string OnClientClick
150 throw new NotImplementedException ();
153 throw new NotImplementedException ();
159 [UrlProperty ("*.aspx")]
164 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
166 public virtual string PostBackUrl
169 throw new NotImplementedException ();
172 throw new NotImplementedException ();
178 [WebSysDescription ("")]
179 [WebCategory ("Behavior")]
180 public virtual string ValidationGroup
183 return ViewState.GetString ("ValidationGroup", "");
186 ViewState ["ValidationGroup"] = value;
192 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
193 #if NET_2_0 && HAVE_CONTROL_ADAPTERS
194 protected virtual new
198 HtmlTextWriterTag TagKey {
199 get { return HtmlTextWriterTag.Input; }
204 protected virtual string Text
207 throw new NotImplementedException ();
210 throw new NotImplementedException ();
215 protected override void AddAttributesToRender (HtmlTextWriter writer)
218 Page.VerifyRenderingInServerForm (this);
220 writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
221 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
222 ClientScriptManager csm = new ClientScriptManager (Page);
223 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
224 writer.AddAttribute ("language", "javascript");
226 base.AddAttributesToRender (writer);
231 protected virtual PostBackOptions GetPostBackOptions ()
233 throw new NotImplementedException ();
240 protected virtual bool LoadPostData (string postDataKey, NameValueCollection psotCollection)
242 throw new NotImplementedException ();
246 protected virtual void RaisePostDataChangedEvent ()
248 throw new NotImplementedException ();
252 protected virtual void RaisePostBackEvent (string eventArgument)
254 throw new NotImplementedException ();
258 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
262 x = postCollection [UniqueID + ".x"];
263 y = postCollection [UniqueID + ".y"];
265 if (x != null && y != null) {
266 pos_x = Int32.Parse(x);
267 pos_y = Int32.Parse(y);
268 Page.RegisterRequiresRaiseEvent (this);
275 void IPostBackDataHandler.RaisePostDataChangedEvent ()
280 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
282 if (CausesValidation)
284 Page.Validate (ValidationGroup);
289 OnClick (new ImageClickEventArgs (pos_x, pos_y));
290 OnCommand (new CommandEventArgs (CommandName, CommandArgument));
293 protected virtual void OnClick (ImageClickEventArgs e)
295 if (Events != null) {
296 EventHandler eh = (EventHandler) (Events [ClickEvent]);
302 protected virtual void OnCommand (CommandEventArgs e)
304 if (Events != null) {
305 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
310 RaiseBubbleEvent (this, e);
318 override void OnPreRender (EventArgs e)
321 Page.RegisterRequiresPostBack (this);
324 [WebSysDescription ("")]
325 [WebCategory ("Action")]
326 public event ImageClickEventHandler Click
329 Events.AddHandler (ClickEvent, value);
332 Events.RemoveHandler (ClickEvent, value);
336 [WebSysDescription ("")]
337 [WebCategory ("Action")]
338 public event CommandEventHandler Command
341 Events.AddHandler (CommandEvent, value);
344 Events.RemoveHandler (CommandEvent, value);
350 string IButtonControl.Text
353 throw new NotImplementedException ();
356 throw new NotImplementedException ();
361 event EventHandler IButtonControl.Click
364 throw new NotImplementedException ();
367 throw new NotImplementedException ();