2
0

HtmlInputButton.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. //
  22. // System.Web.UI.HtmlControls.HtmlInputButton.cs
  23. //
  24. // Authors:
  25. // Jackson Harper ([email protected])
  26. //
  27. // (C) 2005 Novell, Inc.
  28. using System;
  29. using System.ComponentModel;
  30. namespace System.Web.UI.HtmlControls {
  31. [DefaultEventAttribute ("ServerClick")]
  32. public class HtmlInputButton : HtmlInputControl, IPostBackEventHandler {
  33. private static readonly object ServerClickEvent = new object();
  34. public HtmlInputButton () : this ("button")
  35. {
  36. }
  37. public HtmlInputButton (string type) : base (type)
  38. {
  39. }
  40. [DefaultValue(true)]
  41. #if NET_2_0
  42. public virtual
  43. #else
  44. public
  45. #endif
  46. bool CausesValidation {
  47. get {
  48. return ViewState.GetBool ("CausesValidation", true);
  49. }
  50. set {
  51. ViewState ["CausesValidation"] = value;
  52. }
  53. }
  54. #if NET_2_0
  55. [DefaultValue ("")]
  56. [MonoTODO]
  57. public string ValidationGroup
  58. {
  59. get {
  60. throw new NotImplementedException ();
  61. }
  62. set {
  63. throw new NotImplementedException ();
  64. }
  65. }
  66. #endif
  67. #if NET_2_0
  68. [MonoTODO]
  69. protected virtual void RaisePostBackEvent (string eventArgument)
  70. {
  71. throw new NotImplementedException ();
  72. }
  73. #endif
  74. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  75. {
  76. if (CausesValidation)
  77. Page.Validate ();
  78. OnServerClick (EventArgs.Empty);
  79. }
  80. #if NET_2_0
  81. protected internal
  82. #else
  83. protected
  84. #endif
  85. override void OnPreRender (EventArgs e)
  86. {
  87. base.OnPreRender (e);
  88. if (Events [ServerClickEvent] != null)
  89. Page.RequiresPostBackScript ();
  90. }
  91. protected virtual void OnServerClick (EventArgs e)
  92. {
  93. EventHandler server_click = (EventHandler) Events [ServerClickEvent];
  94. if (server_click != null)
  95. server_click (this, e);
  96. }
  97. protected override void RenderAttributes (HtmlTextWriter writer)
  98. {
  99. if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
  100. ClientScriptManager csm = new ClientScriptManager (Page);
  101. writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
  102. writer.WriteAttribute ("language", "javascript");
  103. }
  104. base.RenderAttributes (writer);
  105. }
  106. public event EventHandler ServerClick {
  107. add { Events.AddHandler (ServerClickEvent, value); }
  108. remove { Events.RemoveHandler (ServerClickEvent, value); }
  109. }
  110. }
  111. }