Welcome to mirror list, hosted at ThFree Co, Russian Federation.

HtmlInputImage.cs « System.Web.UI.HtmlControls « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fc690e4f9901a94781db3a7f3f8a9cd0bd085f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*	System.Web.UI.HtmlControls
*	Authors
*		Leen Toelen (toelen@hotmail.com)
*/

using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;

namespace System.Web.UI.HtmlControls{
	
	[DefaultEvent("ServerClick")]
	public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
		
		private static readonly object EventServerClick = new object ();
		private int _x, _y;
		
		public HtmlInputImage(): base("image"){}
		
		protected override void OnPreRender(EventArgs e){
			if (Page != null && !Disabled){
				Page.RegisterRequiresPostBack(this);
			}
		}
		
		protected override void RenderAttributes(HtmlTextWriter writer)
		{
			base.RenderAttributes (writer);
			// Anything else?
		}

		protected virtual void OnServerClick(ImageClickEventArgs e){
			ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
			if (handler != null) handler (this, e);
		}
		
		bool IPostBackDataHandler.LoadPostData (string postDataKey,
						       NameValueCollection postCollection)
		{
			string postX = postCollection[String.Concat(RenderedName,".x")];
			string postY = postCollection[String.Concat(RenderedName,".y")];
			if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
				_x = Int32.Parse(postX, CultureInfo.InvariantCulture);
				_y = Int32.Parse(postY, CultureInfo.InvariantCulture);
				Page.RegisterRequiresRaiseEvent(this);
			}
			return false;
		}
		
		void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
		{
			if (CausesValidation)
				Page.Validate();
			OnServerClick (new ImageClickEventArgs(_x, _y));
		}
		
		void IPostBackDataHandler.RaisePostDataChangedEvent ()
		{
		}
		
		[WebCategory("Action")]
		[WebSysDescription("Fires when the image is clicked.")]
		public event ImageClickEventHandler ServerClick{
			add{
				Events.AddHandler(EventServerClick, value);
			}
			remove{
				Events.RemoveHandler(EventServerClick, value);
			}
		}
		
		[DefaultValue("")]
		[WebCategory("Appearance")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public string Align{
			get{
				string attr = Attributes["align"];
				if (attr != null) return attr;
				return String.Empty;
			}
			set{
				Attributes["align"] = AttributeToString(value);
			}
		}
		
		[DefaultValue("")]
		[WebCategory("Appearance")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public string Alt{
			get{
				string attr = Attributes["alt"];
				if (attr != null) return attr;
				return String.Empty;
			}
			set{
				Attributes["alt"] = AttributeToString(value);
			}
		}
		
		[DefaultValue("")]
		[WebCategory("Appearance")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public int Border{
			get{
				string attr = Attributes["border"];
				if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
				return -1;
			}
			set{
				Attributes["border"] = AttributeToString(value);
			}
		}
		
		[DefaultValue(true)]
		[WebCategory("Behavior")]
		public bool CausesValidation{
			get{
				object causesVal = ViewState["CausesValidation"];
				if (causesVal != null) return (Boolean) causesVal;
				return true;
			}
			set{
				ViewState["CausesValidation"] = (Boolean) value;
			}
		}
		
		[DefaultValue("")]
		[WebCategory("Appearance")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public string Src{
			get{
				string attr = Attributes["src"];
				if (attr != null) return attr;
				return String.Empty;
			}
			set{
				Attributes["src"] = AttributeToString(value);
			}
		}
	} // class HtmlInputImage
} // namespace System.Web.UI.HtmlControls