(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / ImageButton.cs
blobc7e37ee4e334b17a0309afe0c5bbe41027b3bc72
1 //
2 // System.Web.UI.WebControls.ImageButton.cs
3 //
4 // Authors:
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System;
34 using System.Collections;
35 using System.Collections.Specialized;
36 using System.Web;
37 using System.Web.UI;
38 using System.ComponentModel;
40 namespace System.Web.UI.WebControls
42 [DefaultEvent("Click")]
43 public class ImageButton: Image, IPostBackDataHandler, IPostBackEventHandler
45 private static readonly object ClickEvent = new object();
46 private static readonly object CommandEvent = new object();
48 private int x, y;
50 public ImageButton(): base()
54 [DefaultValue (true), Bindable (false), WebCategory ("Behavior")]
55 [WebSysDescription ("Determines if validation is performed when clicked.")]
56 public bool CausesValidation
58 get
60 object o = ViewState["CausesValidation"];
61 if(o!=null)
62 return (bool)o;
63 return true;
65 set
67 ViewState["CausesValidation"] = value;
71 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
72 [WebSysDescription ("An argument for the Command of this control.")]
73 public string CommandArgument
75 get
77 object o = ViewState["CommandArgument"];
78 if(o!=null)
79 return (string)o;
80 return String.Empty;
82 set
84 ViewState["CommandArgument"] = value;
88 [DefaultValue (""), WebCategory ("Behavior")]
89 [WebSysDescription ("The name of the Command of this control.")]
90 public string CommandName
92 get
94 object o = ViewState["CommandName"];
95 if(o!=null)
96 return (string)o;
97 return String.Empty;
99 set
101 ViewState["CommandName"] = value;
105 [Browsable (false)]
106 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
107 protected override HtmlTextWriterTag TagKey
111 return HtmlTextWriterTag.Input;
115 [WebCategory ("Action")]
116 [WebSysDescription ("Raised when the LinkButton is clicked.")]
117 public event ImageClickEventHandler Click
121 Events.AddHandler(ClickEvent, value);
123 remove
125 Events.RemoveHandler(ClickEvent, value);
129 [WebCategory ("Action")]
130 [WebSysDescription ("Raised when a LinkButton Command is executed.")]
131 public event CommandEventHandler Command
135 Events.AddHandler(CommandEvent, value);
137 remove
139 Events.RemoveHandler(CommandEvent, value);
143 protected override void AddAttributesToRender(HtmlTextWriter writer)
145 writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");
146 writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
147 if(Page != null && CausesValidation)
149 if(Page.Validators.Count > 0)
151 writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Utils.GetClientValidatedEvent(Page));
152 writer.AddAttribute("language", "javascript");
155 base.AddAttributesToRender(writer);
158 protected virtual void OnClick(ImageClickEventArgs e)
160 if(Events != null)
162 ImageClickEventHandler iceh = (ImageClickEventHandler)(Events[ClickEvent]);
163 if(iceh != null)
164 iceh(this, e);
168 protected virtual void OnCommand(CommandEventArgs e)
170 if(Events != null)
172 CommandEventHandler ceh = (CommandEventHandler)(Events[CommandEvent]);
173 if(ceh != null)
174 ceh(this, e);
175 RaiseBubbleEvent(this, e);
179 protected override void OnPreRender(EventArgs e)
181 if(Page != null)
183 Page.RegisterRequiresPostBack(this);
187 bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
189 string xCoord = postCollection[UniqueID + ".x"];
190 string yCoord = postCollection[UniqueID + ".y"];
191 string id = postCollection[UniqueID];
192 if(xCoord != null && yCoord != null && xCoord.Length > 0 && yCoord.Length > 0)
194 x = Int32.Parse(xCoord);
195 y = Int32.Parse(yCoord);
196 Page.RegisterRequiresRaiseEvent(this);
197 } else if (id != null)
200 // This is a workaround for bug #49819. It appears that the .x and .y
201 // values are not being posted, and only the x value is being posted
202 // with the ctrl's id as the key.
204 x = Int32.Parse (id);
205 Page.RegisterRequiresRaiseEvent (this);
207 return false;
210 void IPostBackDataHandler.RaisePostDataChangedEvent()
214 void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
216 if(CausesValidation)
217 Page.Validate();
218 OnClick(new ImageClickEventArgs(x, y));
219 OnCommand(new CommandEventArgs(CommandName, CommandArgument));