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-2010 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;
38 using System.Web.Util;
40 namespace System.Web.UI.HtmlControls
43 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 [DefaultEvent("ServerClick")]
47 [SupportsEventValidation]
48 public class HtmlInputImage : HtmlInputControl, IPostBackDataHandler, IPostBackEventHandler
50 static readonly object ServerClickEvent = new object ();
55 public HtmlInputImage () : base ("image")
60 [WebSysDescription("")]
61 [WebCategory("Behavior")]
62 public virtual bool CausesValidation {
64 return ViewState.GetBool ("CausesValidation", true);
67 ViewState ["CausesValidation"] = value;
72 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
73 [WebSysDescription("")]
74 [WebCategory("Appearance")]
76 get { return GetAtt ("align"); }
77 set { SetAtt ("align", value); }
81 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
83 [WebSysDescription("")]
84 [WebCategory("Appearance")]
86 get { return GetAtt ("alt"); }
87 set { SetAtt ("alt", value); }
91 [WebSysDescription("")]
92 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
93 [WebCategory("Appearance")]
96 get { return GetAtt ("src"); }
97 set { SetAtt ("src", value); }
101 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
102 [WebSysDescription("")]
103 [WebCategory("Appearance")]
106 string border = Attributes ["border"];
109 return Int32.Parse (border, Helpers.InvariantCulture);
113 Attributes.Remove ("border");
116 Attributes ["border"] = value.ToString (Helpers.InvariantCulture);
120 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
122 string x = postCollection [UniqueID + ".x"];
123 string y = postCollection [UniqueID + ".y"];
125 if (x != null && x.Length != 0 &&
126 y != null && y.Length != 0) {
127 clicked_x = Int32.Parse (x, Helpers.InvariantCulture);
128 clicked_y = Int32.Parse (y, Helpers.InvariantCulture);
129 Page.RegisterRequiresRaiseEvent (this);
137 void RaisePostBackEventInternal (string eventArgument)
139 if (CausesValidation)
140 Page.Validate (ValidationGroup);
142 OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
145 void RaisePostDataChangedEventInternal ()
147 /* no events to raise */
151 public virtual string ValidationGroup
154 return ViewState.GetString ("ValidationGroup", "");
157 ViewState ["ValidationGroup"] = value;
161 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
163 return LoadPostDataInternal (postDataKey, postCollection);
166 protected virtual void RaisePostBackEvent (string eventArgument)
168 RaisePostBackEventInternal (eventArgument);
171 protected virtual void RaisePostDataChangedEvent ()
173 ValidateEvent (UniqueID, String.Empty);
174 RaisePostDataChangedEventInternal ();
177 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
179 return LoadPostData (postDataKey, postCollection);
182 void IPostBackDataHandler.RaisePostDataChangedEvent ()
184 RaisePostDataChangedEvent();
187 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
189 RaisePostBackEvent (eventArgument);
192 protected internal override void OnPreRender (EventArgs e)
194 base.OnPreRender (e);
197 if (page != null && !Disabled) {
198 page.RegisterRequiresPostBack (this);
199 page.RegisterEnabledControl (this);
203 protected virtual void OnServerClick (ImageClickEventArgs e)
205 ImageClickEventHandler handler = Events [ServerClickEvent] as ImageClickEventHandler;
210 protected override void RenderAttributes (HtmlTextWriter writer)
214 page.ClientScript.RegisterForEventValidation (UniqueID);
216 if (CausesValidation && page != null && page.AreValidatorsUplevel (ValidationGroup)) {
217 ClientScriptManager csm = page.ClientScript;
218 Attributes ["onclick"] += csm.GetClientValidationEvent (ValidationGroup);
221 PreProcessRelativeReference (writer,"src");
222 base.RenderAttributes (writer);
225 void SetAtt (string name, string value)
227 if ((value == null) || (value.Length == 0))
228 Attributes.Remove (name);
230 Attributes [name] = value;
233 string GetAtt (string name)
235 string res = Attributes [name];
241 [WebSysDescription("")]
242 [WebCategory("Action")]
243 public event ImageClickEventHandler ServerClick {
244 add { Events.AddHandler (ServerClickEvent, value); }
245 remove { Events.AddHandler (ServerClickEvent, value); }