HtmlButton.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. namespace System.Web.UI.HtmlControls{
  9. public class HtmlButton : HtmlContainerControl, IPostBackEventHandler{
  10. private static readonly object EventServerClick;
  11. //Checked
  12. static HtmlButton(){
  13. EventServerClick = new Object();
  14. }
  15. //Checked
  16. public HtmlButton(): base("button"){}
  17. //Checked
  18. protected virtual void OnServerClick(EventArgs e){
  19. EventHandler handler;
  20. handler = (EventHandler) Events[EventServerClick];
  21. if(handler != null){
  22. handler.Invoke(this, e);
  23. }
  24. }
  25. protected new void RenderAttributes(HtmlTextWriter writer){
  26. if (Page != null && Events[EventServerClick] != null){
  27. WriteOnClickAttribute(
  28. writer,
  29. false,
  30. true,
  31. CausesValidation == false? Page.Validators.Count > 0: false);
  32. }
  33. base.RenderAttributes(writer);
  34. }
  35. void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(string eventArgument){
  36. if (CausesValidation){
  37. Page.Validate();
  38. }
  39. OnServerClick(EventArgs.Empty);
  40. }
  41. public event EventHandler ServerClick{
  42. add{
  43. Events.AddHandler(EventServerClick, value);
  44. }
  45. remove{
  46. Events.RemoveHandler(EventServerClick, value);
  47. }
  48. }
  49. public bool CausesValidation{
  50. get{
  51. object attr = ViewState["CausesValidation"];
  52. if (attr != null){
  53. return (Boolean) attr;
  54. }
  55. return true;
  56. }
  57. set{
  58. ViewState["CausesValidation"] = (Boolean) value;
  59. }
  60. }
  61. } // class HtmlButton
  62. } // namespace System.Web.UI.HtmlControls