RadioButton.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // System.Web.UI.WebControls.RadioButton.cs
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections.Specialized;
  29. using System.ComponentModel;
  30. using System.Security.Permissions;
  31. namespace System.Web.UI.WebControls {
  32. // CAS
  33. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  34. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  35. // attributes
  36. [Designer ("System.Web.UI.Design.WebControls.CheckBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  37. #if NET_2_0
  38. [SupportsEventValidation]
  39. #endif
  40. public class RadioButton : CheckBox , IPostBackDataHandler
  41. {
  42. public RadioButton () : base ("radio")
  43. {
  44. }
  45. [DefaultValue ("")]
  46. #if NET_2_0
  47. [Themeable (false)]
  48. #endif
  49. [WebSysDescription ("")]
  50. [WebCategory ("Behavior")]
  51. public virtual string GroupName
  52. {
  53. get {
  54. return (ViewState.GetString ("GroupName",
  55. String.Empty));
  56. }
  57. set {
  58. ViewState["GroupName"] = value;
  59. }
  60. }
  61. internal override string NameAttribute
  62. {
  63. get {
  64. string unique = UniqueID;
  65. string gn = GroupName;
  66. int colon = -1;
  67. if (unique != null)
  68. colon = unique.IndexOf (':');
  69. if (colon == -1)
  70. return gn;
  71. return unique.Substring (0, colon + 1) + gn;
  72. }
  73. }
  74. internal string ValueAttribute {
  75. get {
  76. return ViewState.GetString ("Value", String.Empty);
  77. }
  78. set {
  79. ViewState["Value"] = value;
  80. }
  81. }
  82. internal override void InternalAddAttributesToRender (HtmlTextWriter w)
  83. {
  84. base.InternalAddAttributesToRender (w);
  85. string val = ValueAttribute;
  86. if (val == null || val.Length == 0)
  87. val = UniqueID;
  88. w.AddAttribute (HtmlTextWriterAttribute.Value, val);
  89. }
  90. #if NET_2_0
  91. protected internal
  92. #else
  93. protected
  94. #endif
  95. override void OnPreRender (EventArgs e)
  96. {
  97. base.OnPreRender (e);
  98. }
  99. #if NET_2_0
  100. protected override
  101. #endif
  102. bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  103. {
  104. bool old_checked = Checked;
  105. if (postCollection[NameAttribute] == postDataKey) {
  106. Checked = true;
  107. } else {
  108. Checked = false;
  109. }
  110. if (old_checked != Checked) {
  111. return (true);
  112. } else {
  113. return (false);
  114. }
  115. }
  116. #if NET_2_0
  117. protected override
  118. #endif
  119. void RaisePostDataChangedEvent ()
  120. {
  121. #if NET_2_0
  122. if (CausesValidation)
  123. Page.Validate (ValidationGroup);
  124. #endif
  125. OnCheckedChanged (EventArgs.Empty);
  126. }
  127. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
  128. {
  129. return LoadPostData (postDataKey, postCollection);
  130. }
  131. }
  132. }