1 /* System.Web.UI.HtmlControls
\r
3 * Leen Toelen (toelen@hotmail.com)
\r
7 using System.Collections.Specialized;
\r
8 using System.ComponentModel;
\r
9 using System.Globalization;
\r
11 using System.Web.UI;
\r
13 namespace System.Web.UI.HtmlControls{
\r
15 [DefaultEvent("ServerClick")]
\r
16 public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
\r
18 private static readonly object EventServerClick = new object ();
\r
21 public HtmlInputImage(): base("image"){}
\r
23 protected override void OnPreRender(EventArgs e){
\r
24 if (Page != null && !Disabled){
\r
25 Page.RegisterRequiresPostBack(this);
\r
29 protected override void RenderAttributes(HtmlTextWriter writer)
\r
31 base.RenderAttributes (writer);
\r
35 protected virtual void OnServerClick(ImageClickEventArgs e){
\r
36 ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
\r
37 if (handler != null) handler (this, e);
\r
40 bool IPostBackDataHandler.LoadPostData (string postDataKey,
\r
41 NameValueCollection postCollection)
\r
43 string postX = postCollection[String.Concat(RenderedName,".x")];
\r
44 string postY = postCollection[String.Concat(RenderedName,".y")];
\r
45 if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
\r
46 _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
\r
47 _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
\r
48 Page.RegisterRequiresRaiseEvent(this);
\r
53 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
\r
55 if (CausesValidation)
\r
57 OnServerClick (new ImageClickEventArgs(_x, _y));
\r
60 void IPostBackDataHandler.RaisePostDataChangedEvent ()
\r
64 [WebCategory("Action")]
\r
65 [WebSysDescription("Fires when the image is clicked.")]
\r
66 public event ImageClickEventHandler ServerClick{
\r
68 Events.AddHandler(EventServerClick, value);
\r
71 Events.RemoveHandler(EventServerClick, value);
\r
76 [WebCategory("Appearance")]
\r
77 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
78 public string Align{
\r
80 string attr = Attributes["align"];
\r
81 if (attr != null) return attr;
\r
82 return String.Empty;
\r
85 Attributes["align"] = AttributeToString(value);
\r
90 [WebCategory("Appearance")]
\r
91 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
94 string attr = Attributes["alt"];
\r
95 if (attr != null) return attr;
\r
96 return String.Empty;
\r
99 Attributes["alt"] = AttributeToString(value);
\r
104 [WebCategory("Appearance")]
\r
105 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
108 string attr = Attributes["border"];
\r
109 if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
\r
113 Attributes["border"] = AttributeToString(value);
\r
117 [DefaultValue(true)]
\r
118 [WebCategory("Behavior")]
\r
119 public bool CausesValidation{
\r
121 object causesVal = ViewState["CausesValidation"];
\r
122 if (causesVal != null) return (Boolean) causesVal;
\r
126 ViewState["CausesValidation"] = (Boolean) value;
\r
131 [WebCategory("Appearance")]
\r
132 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
135 string attr = Attributes["src"];
\r
136 if (attr != null) return attr;
\r
137 return String.Empty;
\r
140 Attributes["src"] = AttributeToString(value);
\r
143 } // class HtmlInputImage
\r
144 } // namespace System.Web.UI.HtmlControls
\r