1 /* System.Web.UI.HtmlControls
3 * Leen Toelen (toelen@hotmail.com)
7 using System
.Collections
.Specialized
;
8 using System
.ComponentModel
;
9 using System
.Globalization
;
13 namespace System
.Web
.UI
.HtmlControls
{
15 [DefaultEvent("ServerClick")]
16 public class HtmlInputImage
: HtmlInputControl
, IPostBackEventHandler
, IPostBackDataHandler
{
18 private static readonly object EventServerClick
= new object ();
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
);
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);
53 void IPostBackEventHandler
.RaisePostBackEvent (string eventArgument
)
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
{
68 Events
.AddHandler(EventServerClick
, value);
71 Events
.RemoveHandler(EventServerClick
, value);
76 [WebCategory("Appearance")]
77 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
80 string attr
= Attributes
["align"];
81 if (attr
!= null) return attr
;
85 Attributes
["align"] = AttributeToString(value);
90 [WebCategory("Appearance")]
91 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
94 string attr
= Attributes
["alt"];
95 if (attr
!= null) return attr
;
99 Attributes
["alt"] = AttributeToString(value);
104 [WebCategory("Appearance")]
105 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
108 string attr
= Attributes
["border"];
109 if (attr
!= null) return Int32
.Parse(attr
,CultureInfo
.InvariantCulture
);
113 Attributes
["border"] = AttributeToString(value);
118 [WebCategory("Behavior")]
119 public bool CausesValidation
{
121 object causesVal
= ViewState
["CausesValidation"];
122 if (causesVal
!= null) return (Boolean
) causesVal
;
126 ViewState
["CausesValidation"] = (Boolean
) value;
131 [WebCategory("Appearance")]
132 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
135 string attr
= Attributes
["src"];
136 if (attr
!= null) return attr
;
140 Attributes
["src"] = AttributeToString(value);
143 } // class HtmlInputImage
144 } // namespace System.Web.UI.HtmlControls