HtmlButton.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, IPostBackDataHandler{
  10. private static readonly object EventServerChange;
  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. //FIXME: check function
  20. protected override void RenderAttributes(HtmlTextWriter writer){
  21. if (Page != null && Events[EventServerClick] != null){
  22. Util.WriteOnClickAttribute(
  23. writer,
  24. this,
  25. false,
  26. true,
  27. CausesValidation == false? Page.Validators.Count > 0: false);
  28. }
  29. RenderAttributes(writer);
  30. }
  31. //FIXME: not sure about the accessor
  32. public void RaisePostBackEvent(string eventArgument){
  33. if (CausesValidation = false){
  34. Page.Validate();
  35. }
  36. OnServerClick(EventArgs.Empty);
  37. }
  38. public event EventHandler ServerClick{
  39. add{
  40. Events.AddHandler(EventServerClick, value);
  41. }
  42. remove{
  43. Events.RemoveHandler(EventServerClick, value);
  44. }
  45. }
  46. public bool CausesValidation{
  47. get{
  48. object causesVal = ViewState["CausesValidation"];
  49. if (causesVal != null){
  50. return (Boolean) causesVal;
  51. }
  52. return 1;
  53. }
  54. set{
  55. ViewState["CausesValidation"] = (Boolean) value;
  56. }
  57. }
  58. } // class HtmlButton
  59. } // namespace System.Web.UI.HtmlControls