HtmlInputButton.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.ComponentModel;
  7. using System.Globalization;
  8. using System.Web;
  9. using System.Web.UI;
  10. namespace System.Web.UI.HtmlControls{
  11. [DefaultEvent("ServerClick")]
  12. public class HtmlInputButton : HtmlInputControl, IPostBackEventHandler{
  13. private static readonly object EventServerClick = new object ();
  14. public HtmlInputButton(): base ("button")
  15. {
  16. }
  17. public HtmlInputButton(string type): base(type){}
  18. protected override void OnPreRender (EventArgs e)
  19. {
  20. base.OnPreRender(e);
  21. }
  22. protected override void RenderAttributes (HtmlTextWriter writer)
  23. {
  24. base.RenderAttributes (writer);
  25. }
  26. protected virtual void OnServerClick(EventArgs e){
  27. EventHandler handler = (EventHandler) Events[EventServerClick];
  28. if (handler != null){
  29. handler.Invoke(this, e);
  30. }
  31. }
  32. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  33. {
  34. if(CausesValidation == true){
  35. Page.Validate();
  36. }
  37. OnServerClick(EventArgs.Empty);
  38. }
  39. [WebCategory("Action")]
  40. [WebSysDescription("Fires when the control is clicked.")]
  41. public event EventHandler ServerClick{
  42. add{
  43. Events.AddHandler(EventServerClick, value);
  44. }
  45. remove{
  46. Events.RemoveHandler(EventServerClick, value);
  47. }
  48. }
  49. [DefaultValue(true)]
  50. [WebCategory("Behavior")]
  51. public bool CausesValidation{
  52. get{
  53. object causesVal = ViewState["CausesValidation"];
  54. if (causesVal != null){
  55. return (Boolean) causesVal;
  56. }
  57. return true;
  58. }
  59. set{
  60. ViewState["CausesValidation"] = (Boolean) value;
  61. }
  62. }
  63. } // end of System.Web.UI.HtmlControls.HtmlInputButton
  64. } // namespace System.Web.UI.HtmlControls