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

RadioButton.cs « System.Web.UI.WebControls « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c999695a8aa0afd93afa00cb44fca7f586277577 (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
/**
 * Namespace: System.Web.UI.WebControls
 * Class:     RadioButton
 *
 * Author:  Gaurav Vaish
 * Maintainer: gvaish@iitk.ac.in
 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
 * Implementation: yes
 * Status:  100%
 *
 * (C) Gaurav Vaish (2001)
 */

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

namespace System.Web.UI.WebControls
{
	//[Designer("??")]
	public class RadioButton : CheckBox, IPostBackDataHandler
	{
		public RadioButton () : base ()
		{
		}

		public virtual string GroupName
		{
			get {
				object o = ViewState ["GroupName"];
				return (o == null) ? String.Empty : (string) o;
			}

			set { ViewState ["GroupName"] = value; }
		}

		protected override void OnPreRender (EventArgs e)
		{
			base.OnPreRender (e);
			if (Page != null && Enabled && !Checked)
				Page.RegisterRequiresPostBack (this);

			if(GroupName.Length == 0)
				GroupName = UniqueID;
		}

		internal override void RenderInputTag (HtmlTextWriter writer, string id)
		{
			writer.AddAttribute (HtmlTextWriterAttribute.Id, id);
			writer.AddAttribute (HtmlTextWriterAttribute.Type, "radio");
			writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueGroupNamePrivate);
			writer.AddAttribute (HtmlTextWriterAttribute.Value, ValueAttributePrivate);

			if (Checked)
				writer.AddAttribute (HtmlTextWriterAttribute.Checked, "checked");

			if (AutoPostBack){
				writer.AddAttribute (HtmlTextWriterAttribute.Onclick,
						     Page.GetPostBackClientEvent (this, ""));
				writer.AddAttribute ("language", "javascript");
			}

			if (AccessKey.Length > 0)
				writer.AddAttribute (HtmlTextWriterAttribute.Accesskey, AccessKey);

			if (TabIndex > 0)
				writer.AddAttribute (HtmlTextWriterAttribute.Tabindex,
						     TabIndex.ToString (NumberFormatInfo.InvariantInfo));

			writer.RenderBeginTag (System.Web.UI.HtmlTextWriterTag.Input);
			writer.RenderEndTag ();
		}

		private string UniqueGroupNamePrivate
		{
			get {
				string retVal = GroupName;
				int unique = UniqueID.LastIndexOf (':');
				if (unique >= 0)
					retVal += UniqueID.Substring (unique + 1);

				return retVal;
			}
		}

		private string ValueAttributePrivate
		{
			get {
				string retVal = Attributes ["value"];
				if (retVal != null)
					return retVal;

				if (ID != null)
					return ID;

				return UniqueID;
			}
		}

		bool IPostBackDataHandler.LoadPostData (string postDataKey,
						        NameValueCollection postCollection)
		{
			bool _checked = Checked;
			if (postCollection [UniqueGroupNamePrivate] == ValueAttributePrivate){
				if (_checked)
					return false;
				Checked = true;
				return true;
			}

			if (_checked)
				Checked = false;
			return true;
		}

		void IPostBackDataHandler.RaisePostDataChangedEvent ()
		{
			OnCheckedChanged (EventArgs.Empty);
		}
	}
}