**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputImage.cs
blobfc690e4f9901a94781db3a7f3f8a9cd0bd085f8a
1 /* System.Web.UI.HtmlControls
2 * Authors
3 * Leen Toelen (toelen@hotmail.com)
4 */
6 using System;
7 using System.Collections.Specialized;
8 using System.ComponentModel;
9 using System.Globalization;
10 using System.Web;
11 using System.Web.UI;
13 namespace System.Web.UI.HtmlControls{
15 [DefaultEvent("ServerClick")]
16 public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
18 private static readonly object EventServerClick = new object ();
19 private int _x, _y;
21 public HtmlInputImage(): base("image"){}
23 protected override void OnPreRender(EventArgs e){
24 if (Page != null && !Disabled){
25 Page.RegisterRequiresPostBack(this);
29 protected override void RenderAttributes(HtmlTextWriter writer)
31 base.RenderAttributes (writer);
32 // Anything else?
35 protected virtual void OnServerClick(ImageClickEventArgs e){
36 ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
37 if (handler != null) handler (this, e);
40 bool IPostBackDataHandler.LoadPostData (string postDataKey,
41 NameValueCollection postCollection)
43 string postX = postCollection[String.Concat(RenderedName,".x")];
44 string postY = postCollection[String.Concat(RenderedName,".y")];
45 if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
46 _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
47 _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
48 Page.RegisterRequiresRaiseEvent(this);
50 return false;
53 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
55 if (CausesValidation)
56 Page.Validate();
57 OnServerClick (new ImageClickEventArgs(_x, _y));
60 void IPostBackDataHandler.RaisePostDataChangedEvent ()
64 [WebCategory("Action")]
65 [WebSysDescription("Fires when the image is clicked.")]
66 public event ImageClickEventHandler ServerClick{
67 add{
68 Events.AddHandler(EventServerClick, value);
70 remove{
71 Events.RemoveHandler(EventServerClick, value);
75 [DefaultValue("")]
76 [WebCategory("Appearance")]
77 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
78 public string Align{
79 get{
80 string attr = Attributes["align"];
81 if (attr != null) return attr;
82 return String.Empty;
84 set{
85 Attributes["align"] = AttributeToString(value);
89 [DefaultValue("")]
90 [WebCategory("Appearance")]
91 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
92 public string Alt{
93 get{
94 string attr = Attributes["alt"];
95 if (attr != null) return attr;
96 return String.Empty;
98 set{
99 Attributes["alt"] = AttributeToString(value);
103 [DefaultValue("")]
104 [WebCategory("Appearance")]
105 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
106 public int Border{
107 get{
108 string attr = Attributes["border"];
109 if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
110 return -1;
112 set{
113 Attributes["border"] = AttributeToString(value);
117 [DefaultValue(true)]
118 [WebCategory("Behavior")]
119 public bool CausesValidation{
120 get{
121 object causesVal = ViewState["CausesValidation"];
122 if (causesVal != null) return (Boolean) causesVal;
123 return true;
125 set{
126 ViewState["CausesValidation"] = (Boolean) value;
130 [DefaultValue("")]
131 [WebCategory("Appearance")]
132 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
133 public string Src{
134 get{
135 string attr = Attributes["src"];
136 if (attr != null) return attr;
137 return String.Empty;
139 set{
140 Attributes["src"] = AttributeToString(value);
143 } // class HtmlInputImage
144 } // namespace System.Web.UI.HtmlControls