HtmlInputButton.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. WriteOnClickAttribute(
  32. writer,
  33. false,
  34. true,
  35. CausesValidation == false? Page.Validators.Count > 0: false);
  36. }
  37. else{
  38. if (events != true && String.Compare(attrType,"button", true) != 0){
  39. WriteOnClickAttribute(
  40. writer,
  41. false,
  42. true,
  43. CausesValidation == false? Page.Validators.Count > 0: false);
  44. }
  45. }
  46. }
  47. base.RenderAttributes(writer);
  48. }
  49. public void RaisePostBackEvent(string eventArgument){
  50. if(CausesValidation == true){
  51. Page.Validate();
  52. }
  53. OnServerClick(EventArgs.Empty);
  54. }
  55. public event EventHandler ServerClick{
  56. add{
  57. Events.AddHandler(EventServerClick, value);
  58. }
  59. remove{
  60. Events.RemoveHandler(EventServerClick, value);
  61. }
  62. }
  63. public bool CausesValidation{
  64. get{
  65. object causesVal = ViewState["CausesValidation"];
  66. if (causesVal != null){
  67. return (Boolean) causesVal;
  68. }
  69. return true;
  70. }
  71. set{
  72. ViewState["CausesValidation"] = (Boolean) value;
  73. }
  74. }
  75. } // end of System.Web.UI.HtmlControls.HtmlInputButton
  76. } // namespace System.Web.UI.HtmlControls