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, IPostBackEventHandler
51 static readonly object ServerClickEvent = new object ();
56 public HtmlInputImage () : base ("image")
61 [WebSysDescription("")]
62 [WebCategory("Behavior")]
68 bool CausesValidation {
70 return ViewState.GetBool ("CausesValidation", true);
73 ViewState ["CausesValidation"] = value;
78 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
79 [WebSysDescription("")]
80 [WebCategory("Appearance")]
82 get { return GetAtt ("align"); }
83 set { SetAtt ("align", value); }
87 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
91 [WebSysDescription("")]
92 [WebCategory("Appearance")]
94 get { return GetAtt ("alt"); }
95 set { SetAtt ("alt", value); }
99 [WebSysDescription("")]
100 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
101 [WebCategory("Appearance")]
106 get { return GetAtt ("src"); }
107 set { SetAtt ("src", value); }
115 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
116 [WebSysDescription("")]
117 [WebCategory("Appearance")]
120 string border = Attributes ["border"];
123 return Int32.Parse (border, CultureInfo.InvariantCulture);
127 Attributes.Remove ("border");
130 Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
134 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
136 string x = postCollection [UniqueID + ".x"];
137 string y = postCollection [UniqueID + ".y"];
139 if (x != null && x.Length != 0 &&
140 y != null && y.Length != 0) {
141 clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
142 clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
143 Page.RegisterRequiresRaiseEvent (this);
151 void RaisePostBackEventInternal (string eventArgument)
153 if (CausesValidation)
155 Page.Validate (ValidationGroup);
159 OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
162 void RaisePostDataChangedEventInternal ()
164 /* no events to raise */
169 public virtual string ValidationGroup
172 return ViewState.GetString ("ValidationGroup", "");
175 ViewState ["ValidationGroup"] = value;
179 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
181 return LoadPostDataInternal (postDataKey, postCollection);
184 protected virtual void RaisePostBackEvent (string eventArgument)
186 RaisePostBackEventInternal (eventArgument);
189 protected virtual void RaisePostDataChangedEvent ()
191 ValidateEvent (UniqueID, String.Empty);
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);
234 if (Page != null && !Disabled) {
235 Page.RegisterRequiresPostBack (this);
237 Page.RegisterEnabledControl (this);
242 protected virtual void OnServerClick (ImageClickEventArgs e)
244 ImageClickEventHandler handler = Events [ServerClickEvent] as ImageClickEventHandler;
249 protected override void RenderAttributes (HtmlTextWriter writer)
253 Page.ClientScript.RegisterForEventValidation (UniqueID);
255 if (CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup)) {
256 ClientScriptManager csm = Page.ClientScript;
257 Attributes ["onclick"] += csm.GetClientValidationEvent (ValidationGroup);
260 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
261 ClientScriptManager csm = new ClientScriptManager (Page);
262 writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
266 PreProcessRelativeReference (writer,"src");
267 base.RenderAttributes (writer);
270 void SetAtt (string name, string value)
272 if ((value == null) || (value.Length == 0))
273 Attributes.Remove (name);
275 Attributes [name] = value;
278 string GetAtt (string name)
280 string res = Attributes [name];
286 [WebSysDescription("")]
287 [WebCategory("Action")]
288 public event ImageClickEventHandler ServerClick {
289 add { Events.AddHandler (ServerClickEvent, value); }
290 remove { Events.AddHandler (ServerClickEvent, value); }