2
0

HtmlInputCheckBox.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 postChecked = false;
  17. if (postValue != null)
  18. postChecked = postValue.Length > 0;
  19. Checked = postChecked;
  20. return (postChecked == Checked == false);
  21. }
  22. public void RaisePostDataChangedEvent(){
  23. OnServerChange(EventArgs.Empty);
  24. }
  25. protected void OnServerChange(EventArgs e){
  26. EventHandler handler = (EventHandler) Events[EventServerChange];
  27. if (handler != null) handler.Invoke(this, e);
  28. }
  29. protected override void OnPreRender(EventArgs e){
  30. if (Page != null && !Disabled)
  31. Page.RegisterRequiresPostBack(this);
  32. if (Events[EventServerChange] != null && !Disabled)
  33. ViewState.SetItemDirty("checkbox",false);
  34. }
  35. public event EventHandler ServerChange{
  36. add{
  37. Events.AddHandler(EventServerChange, value);
  38. }
  39. remove{
  40. Events.RemoveHandler(EventServerChange, value);
  41. }
  42. }
  43. public bool Checked{
  44. get{
  45. string attr = Attributes["checked"];
  46. if (attr != null)
  47. return attr.Equals("checked");
  48. return false;
  49. }
  50. set{
  51. Attributes["checked"] = (value == true)? "checked": null;
  52. }
  53. }
  54. } // class HtmlInputCheckBox
  55. } // namespace System.Web.UI.HtmlControls