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);
132 public string ValidationGroup
135 throw new NotImplementedException ();
138 throw new NotImplementedException ();
143 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
145 throw new NotImplementedException ();
149 protected virtual void RaisePostBackEvent (string eventArgument)
151 throw new NotImplementedException ();
155 protected virtual void RaisePostDataChangedEvent ()
157 throw new NotImplementedException ();
161 bool IPostBackDataHandler.LoadPostData (string postDataKey,
162 NameValueCollection postCollection)
164 string x = postCollection [UniqueID + ".x"];
165 string y = postCollection [UniqueID + ".y"];
167 if (x != null && x.Length != 0 &&
168 y != null && y.Length != 0) {
169 clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
170 clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
171 Page.RegisterRequiresRaiseEvent (this);
179 void IPostBackDataHandler.RaisePostDataChangedEvent ()
183 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
185 if (CausesValidation)
187 Page.Validate (ValidationGroup);
191 OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
199 override void OnPreRender (EventArgs e)
201 base.OnPreRender (e);
203 Page.RegisterRequiresPostBack (this);
206 protected virtual void OnServerClick (ImageClickEventArgs e)
208 EventHandler handler = Events [ServerClickEvent] as EventHandler;
213 protected override void RenderAttributes (HtmlTextWriter writer)
215 if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
216 ClientScriptManager csm = new ClientScriptManager (Page);
217 writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
220 base.RenderAttributes (writer);
223 private void SetAtt (string name, string value)
226 Attributes.Remove (name);
228 Attributes [name] = value;
231 private string GetAtt (string name)
233 string res = Attributes [name];
239 [WebSysDescription("")]
240 [WebCategory("Action")]
241 public event ImageClickEventHandler ServerClick {
242 add { Events.AddHandler (ServerClickEvent, value); }
243 remove { Events.AddHandler (ServerClickEvent, value); }