2 // Permission is hereby granted, free of charge, to any person obtaining
3 // a copy of this software and associated documentation files (the
4 // "Software"), to deal in the Software without restriction, including
5 // without limitation the rights to use, copy, modify, merge, publish,
6 // distribute, sublicense, and/or sell copies of the Software, and to
7 // permit persons to whom the Software is furnished to do so, subject to
8 // the following conditions:
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // System.Web.UI.HtmlControls.HtmlInputImage.cs
25 // Jackson Harper (jackson@ximian.com)
27 // (C) 2005 Novell, Inc.
31 // TODO: getting the .x and .y in LoadData doesn't work with mozilla
34 using System.Globalization;
35 using System.Collections.Specialized;
36 using System.ComponentModel;
37 using System.Security.Permissions;
39 namespace System.Web.UI.HtmlControls {
42 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
45 [DefaultEvent("ServerClick")]
47 [SupportsEventValidation]
49 public class HtmlInputImage : HtmlInputControl, IPostBackDataHandler,
50 IPostBackEventHandler {
52 private static readonly object ServerClickEvent = new object ();
54 private int clicked_x;
55 private int clicked_y;
57 public HtmlInputImage () : base ("image")
62 [WebSysDescription("")]
63 [WebCategory("Behavior")]
69 bool CausesValidation {
71 return ViewState.GetBool ("CausesValidation", true);
74 ViewState ["CausesValidation"] = value;
79 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
80 [WebSysDescription("")]
81 [WebCategory("Appearance")]
83 get { return GetAtt ("align"); }
84 set { SetAtt ("align", value); }
88 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
92 [WebSysDescription("")]
93 [WebCategory("Appearance")]
95 get { return GetAtt ("alt"); }
96 set { SetAtt ("alt", value); }
100 [WebSysDescription("")]
101 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
102 [WebCategory("Appearance")]
107 get { return GetAtt ("src"); }
108 set { SetAtt ("src", value); }
116 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
117 [WebSysDescription("")]
118 [WebCategory("Appearance")]
121 string border = Attributes ["border"];
124 return Int32.Parse (border, CultureInfo.InvariantCulture);
128 Attributes.Remove ("border");
131 Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
135 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
137 string x = postCollection [UniqueID + ".x"];
138 string y = postCollection [UniqueID + ".y"];
140 if (x != null && x.Length != 0 &&
141 y != null && y.Length != 0) {
142 clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
143 clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
144 Page.RegisterRequiresRaiseEvent (this);
152 void RaisePostBackEventInternal (string eventArgument)
154 if (CausesValidation)
156 Page.Validate (ValidationGroup);
160 OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
163 void RaisePostDataChangedEventInternal ()
165 /* no events to raise */
170 public virtual string ValidationGroup
173 return ViewState.GetString ("ValidationGroup", "");
176 ViewState ["ValidationGroup"] = value;
180 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
182 return LoadPostDataInternal (postDataKey, postCollection);
185 protected virtual void RaisePostBackEvent (string eventArgument)
187 RaisePostBackEventInternal (eventArgument);
190 protected virtual void RaisePostDataChangedEvent ()
192 RaisePostDataChangedEventInternal ();
196 bool IPostBackDataHandler.LoadPostData (string postDataKey,
197 NameValueCollection postCollection)
200 return LoadPostData (postDataKey, postCollection);
202 return LoadPostDataInternal (postDataKey, postCollection);
207 void IPostBackDataHandler.RaisePostDataChangedEvent ()
210 RaisePostDataChangedEvent();
212 RaisePostDataChangedEventInternal ();
216 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
219 RaisePostBackEvent (eventArgument);
221 RaisePostBackEventInternal (eventArgument);
230 override void OnPreRender (EventArgs e)
232 base.OnPreRender (e);
235 Page.RegisterRequiresPostBack (this);
239 protected virtual void OnServerClick (ImageClickEventArgs e)
241 EventHandler handler = Events [ServerClickEvent] as EventHandler;
246 protected override void RenderAttributes (HtmlTextWriter writer)
250 Page.ClientScript.RegisterForEventValidation (this.UniqueID);
252 if (CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup)) {
253 ClientScriptManager csm = Page.ClientScript;
254 Attributes ["onclick"] += csm.GetClientValidationEvent (ValidationGroup);
257 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
258 ClientScriptManager csm = new ClientScriptManager (Page);
259 writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
263 base.RenderAttributes (writer);
266 private void SetAtt (string name, string value)
268 if ((value == null) || (value.Length == 0))
269 Attributes.Remove (name);
271 Attributes [name] = value;
274 private string GetAtt (string name)
276 string res = Attributes [name];
282 [WebSysDescription("")]
283 [WebCategory("Action")]
284 public event ImageClickEventHandler ServerClick {
285 add { Events.AddHandler (ServerClickEvent, value); }
286 remove { Events.AddHandler (ServerClickEvent, value); }