2
0

HtmlInputButton.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. using System.Globalization;
  9. namespace System.Web.UI.HtmlControls{
  10. public class HtmlInputButton : HtmlInputControl, IPostBackEventHandler{
  11. private static readonly object EventServerClick;
  12. public HtmlInputButton(string type): base(type){}
  13. protected void OnServerClick(EventArgs e){
  14. EventHandler handler = (EventHandler) Events[EventServerClick];
  15. if (handler != null){
  16. handler.Invoke(this, e);
  17. }
  18. }
  19. protected override void RenderAttributes(HtmlTextWriter writer){
  20. string attrType = Type;
  21. bool ofTypeSubmit = (String.Compare(attrType, "submit", true) == 0);
  22. bool events;
  23. if (ofTypeSubmit != true){
  24. events = (Events[EventServerClick] != null);
  25. }
  26. else{
  27. events = false;
  28. }
  29. if (Page != null){
  30. if (ofTypeSubmit != true){
  31. System.Web.UI.Util.WriteOnClickAttribute(
  32. writer,
  33. this,
  34. false,
  35. true,
  36. CausesValidation == false? Page.Validators.Count > 0: false);
  37. }
  38. else{
  39. if (events != true && String.Compare(attrType,"button", true) != 0){
  40. System.Web.UI.Util.WriteOnClickAttribute(
  41. writer,
  42. this,
  43. false,
  44. true,
  45. CausesValidation == false? Page.Validators.Count > 0: false);
  46. }
  47. }
  48. }
  49. base.RenderAttributes(writer);
  50. }
  51. public void RaisePostBackEvent(string eventArgument){
  52. if(CausesValidation == true){
  53. Page.Validate();
  54. }
  55. OnServerClick(EventArgs.Empty);
  56. }
  57. public event EventHandler ServerClick{
  58. add{
  59. Events.AddHandler(EventServerClick, value);
  60. }
  61. remove{
  62. Events.RemoveHandler(EventServerClick, value);
  63. }
  64. }
  65. public bool CausesValidation{
  66. get{
  67. object causesVal = ViewState["CausesValidation"];
  68. if (causesVal != null){
  69. return (Boolean) causesVal;
  70. }
  71. return true;
  72. }
  73. set{
  74. ViewState["CausesValidation"] = (Boolean) value;
  75. }
  76. }
  77. } // end of System.Web.UI.HtmlControls.HtmlInputButton
  78. } // namespace System.Web.UI.HtmlControls