HtmlInputCheckBox.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Globalization;
  9. using System.Collections.Specialized;
  10. namespace System.Web.UI.HtmlControls{
  11. public class HtmlInputCheckBox : HtmlInputControl, IPostBackDataHandler{
  12. private static readonly object EventServerChange;
  13. public HtmlInputCheckBox: base("checkbox"){}
  14. public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
  15. string postValue = postCollection[postDataKey];
  16. bool greaterthan;
  17. if (postValue != null){
  18. greaterthan = postValue.Length > 0;
  19. }
  20. else{
  21. greaterthan = false;
  22. }
  23. bool equalcheck = greaterthan == Checked == false;
  24. Checked = greaterthan;
  25. return equalcheck;
  26. }
  27. public override void RaisePostDataChangedEvent(){
  28. OnServerChange(EventArgs.Empty);
  29. }
  30. protected void OnServerChange(EventArgs e){
  31. EventHandler handler = (EventHandler) Events[EventServerChange];
  32. if (handler != null){
  33. handler.Invoke(this, e);
  34. }
  35. }
  36. protected void OnPreRender(EventArgs e){
  37. if (Page != null && !Disabled){
  38. Page.RegisterRequiresPostBack(this);
  39. }
  40. if (Events[EventServerChange] != null && !Disabled){
  41. ViewState.SetItemDirty("checkbox",false);
  42. }
  43. }
  44. public event EventHandler ServerChange{
  45. add{
  46. Events.AddHandler(EventServerChange, value);
  47. }
  48. remove{
  49. Events.RemoveHandler(EventServerChange, value);
  50. }
  51. }
  52. public bool Checked{
  53. get{
  54. string attr = Attributes["checked"];
  55. if (attr != null){
  56. return attr.Equals("checked");
  57. }
  58. return false;
  59. }
  60. set{
  61. if (value != true){
  62. Attributes["checked"] = null;
  63. }
  64. Attributes["checked"] = "checked";
  65. }
  66. }
  67. } // class HtmlInputCheckBox
  68. } // namespace System.Web.UI.HtmlControls