2
0

HtmlButton.cs 1.6 KB

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