HtmlButton.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* System.Web.Configuration
  2. * Authors:
  3. * Leen Toelen ([email protected])
  4. * Copyright (C) 2001 Leen Toelen
  5. */
  6. using System;
  7. using System.Web;
  8. using System.Web.UI;
  9. namespace System.Web.UI.HtmlControls{
  10. public class HtmlButton : HtmlContainerControl, IPostBackDataHandler{
  11. private static object EventServerClick = new Object();
  12. public HtmlButton(): base("button"){}
  13. protected virtual void OnServerClick(EventArgs e){
  14. EventHandler handler;
  15. handler = (EventHandler) Events[EventServerClick];
  16. if(handler != null){
  17. handler.Invoke(this, e);
  18. }
  19. }
  20. //FIXME: check function
  21. protected override void RenderAttributes(HtmlTextWriter writer){
  22. if (Page != null && Events[EventServerClick] != null){
  23. Util.WriteOnClickAttribute(
  24. writer,
  25. this,
  26. false,
  27. true,
  28. CausesValidation == false? Page.Validators.Count > 0: false);
  29. }
  30. RenderAttributes(writer);
  31. }
  32. //FIXME: not sure about the accessor
  33. public void RaisePostBackEvent(string eventArgument){
  34. if (CausesValidation = false){
  35. Page.Validate();
  36. }
  37. OnServerClick(EventArgs.Empty);
  38. }
  39. public event EventHandler ServerClick{
  40. add{
  41. Events.AddHandler(EventServerClick, value);
  42. }
  43. remove{
  44. Events.RemoveHandler(EventServerClick, value);
  45. }
  46. }
  47. public bool CausesValidation{
  48. get{
  49. object causesVal = ViewState["CausesValidation"];
  50. if (causesVal != null){
  51. return (Boolean) causesVal;
  52. }
  53. return 1;
  54. }
  55. set{
  56. ViewState["CausesValidation"] = (Boolean) value;
  57. }
  58. }
  59. } // class HtmlButton
  60. } // namespace System.Web.UI.HtmlControls