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")]
46 public class HtmlInputImage : HtmlInputControl, IPostBackDataHandler,
47 IPostBackEventHandler {
49 private static readonly object ServerClickEvent = new object ();
51 private int clicked_x;
52 private int clicked_y;
54 public HtmlInputImage () : base ("image")
59 [WebSysDescription("")]
60 [WebCategory("Behavior")]
66 bool CausesValidation {
68 return ViewState.GetBool ("CausesValidation", true);
71 ViewState ["CausesValidation"] = value;
76 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
77 [WebSysDescription("")]
78 [WebCategory("Appearance")]
80 get { return GetAtt ("align"); }
81 set { SetAtt ("align", value); }
85 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
89 [WebSysDescription("")]
90 [WebCategory("Appearance")]
92 get { return GetAtt ("alt"); }
93 set { SetAtt ("alt", value); }
97 [WebSysDescription("")]
98 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
99 [WebCategory("Appearance")]
101 get { return GetAtt ("src"); }
102 set { SetAtt ("src", value); }
110 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
111 [WebSysDescription("")]
112 [WebCategory("Appearance")]
115 string border = Attributes ["border"];
118 return Int32.Parse (border, CultureInfo.InvariantCulture);
122 Attributes.Remove ("border");
125 Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
129 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
131 string x = postCollection [UniqueID + ".x"];
132 string y = postCollection [UniqueID + ".y"];
134 if (x != null && x.Length != 0 &&
135 y != null && y.Length != 0) {
136 clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
137 clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
138 Page.RegisterRequiresRaiseEvent (this);
146 void RaisePostBackEventInternal (string eventArgument)
148 if (CausesValidation)
150 Page.Validate (ValidationGroup);
154 OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
157 void RaisePostDataChangedEventInternal ()
159 /* no events to raise */
164 public string ValidationGroup
167 return ViewState.GetString ("ValidationGroup", "");
170 ViewState ["ValidationGroup"] = value;
174 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
176 return LoadPostDataInternal (postDataKey, postCollection);
179 protected virtual void RaisePostBackEvent (string eventArgument)
181 RaisePostBackEventInternal (eventArgument);
184 protected virtual void RaisePostDataChangedEvent ()
186 RaisePostDataChangedEventInternal ();
190 bool IPostBackDataHandler.LoadPostData (string postDataKey,
191 NameValueCollection postCollection)
194 return LoadPostData (postDataKey, postCollection);
196 return LoadPostDataInternal (postDataKey, postCollection);
201 void IPostBackDataHandler.RaisePostDataChangedEvent ()
204 RaisePostDataChangedEvent();
206 RaisePostDataChangedEventInternal ();
210 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
213 RaisePostBackEvent (eventArgument);
215 RaisePostBackEventInternal (eventArgument);
224 override void OnPreRender (EventArgs e)
226 base.OnPreRender (e);
229 Page.RegisterRequiresPostBack (this);
233 protected virtual void OnServerClick (ImageClickEventArgs e)
235 EventHandler handler = Events [ServerClickEvent] as EventHandler;
240 protected override void RenderAttributes (HtmlTextWriter writer)
242 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
243 ClientScriptManager csm = new ClientScriptManager (Page);
244 writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
247 base.RenderAttributes (writer);
250 private void SetAtt (string name, string value)
253 Attributes.Remove (name);
255 Attributes [name] = value;
258 private string GetAtt (string name)
260 string res = Attributes [name];
266 [WebSysDescription("")]
267 [WebCategory("Action")]
268 public event ImageClickEventHandler ServerClick {
269 add { Events.AddHandler (ServerClickEvent, value); }
270 remove { Events.AddHandler (ServerClickEvent, value); }