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

HtmlInputRadioButton.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: 780988a8bf11d84bfef4b72cebf0b64f1318335a (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
/*	System.Web.UI.HtmlControls
*	Authors
*		Leen Toelen (toelen@hotmail.com)
*/

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

namespace System.Web.UI.HtmlControls{
	
	public class HtmlInputRadioButton : HtmlInputControl, IPostBackDataHandler{
		
		private static readonly object EventServerChange;
		
		public HtmlInputRadioButton(): base("radio"){}
		
		protected override void OnPreRender(EventArgs e){
			if (Page != null && !Disabled){
				Page.RegisterRequiresPostBack(this);
			}
			if (Events[EventServerChange] != null && !Disabled){
				ViewState.SetItemDirty("checked", false);
			}
		}
		
		protected void OnServerChange(EventArgs e){
			EventHandler handler = (EventHandler) Events[EventServerChange];
			if (handler != null){
				handler.Invoke(this, e);
			}
		}
		
		protected override void RenderAttributes(HtmlTextWriter writer){
			writer.WriteAttribute("value", Value);
			Attributes.Remove("value");
			base.RenderAttributes(writer);
		}
		
		public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
			string postValue = postCollection[postDataKey];
			bool myBool = false;
			if (postValue != null && postValue.Equals(Value)){
				if (!Checked){
					Checked = true;
					myBool = true;
				}
			}
			else{
				if (Checked){
					Checked = false;
					myBool = false;
				}
			}
			return myBool;
		}
		
		public void RaisePostDataChangedEvent(){
			OnServerChange(EventArgs.Empty);
		}
		
		public event EventHandler ServerChange{
			add{
				Events.AddHandler(EventServerChange, value);
			}
			remove{
				Events.RemoveHandler(EventServerChange, value);
			}
		}
		
		public bool Checked{
			get{
				string attr = Attributes["checked"];
				if (attr != null){
					return attr.Equals("checked");
				}
				return false;
			}
			set{
				if (value != true){
					Attributes["checked"] = null;
				}
				Attributes["checked"] = "checked";
			}
		}
		public override string Name
		{
			get {
				string attr = Attributes ["name"]; // Gotta use "name" to group radio buttons
				return (attr == null) ? String.Empty : attr;
			}
			set { Attributes ["name"] = value; }
		}
		
		protected override string RenderedName{
			get{
				string attr = base.RenderedName;
				string id = UniqueID;
				int indexOfX = id.LastIndexOf('X');
				if (indexOfX != 0 && indexOfX >= 0){
					attr = String.Concat(attr, id.Substring(0,indexOfX+1));
				}
				return attr;
			}
		}

		public override string Value
		{
			get {
				string v = Attributes ["value"];
				if (v != null && v != "")
					return v;
				v = ID;
				Attributes ["value"] = v;
				return v;
			}

			set { Attributes ["value"] = value; }
		}
		
	} // class HtmlInputRadioButton
} // namespace System.Web.UI.HtmlControls