HtmlButton.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, IPostBackEventHandler{
  10. private static readonly object EventServerClick;
  11. //Checked
  12. static HtmlButton(){
  13. EventServerClick = new Object();
  14. }
  15. //Checked
  16. public HtmlButton(): base("button"){}
  17. //Checked
  18. protected virtual void OnServerClick(EventArgs e){
  19. EventHandler handler;
  20. handler = (EventHandler) Events[EventServerClick];
  21. if(handler != null){
  22. handler.Invoke(this, e);
  23. }
  24. }
  25. protected override void RenderAttributes(HtmlTextWriter writer){
  26. if (Page != null && Events[EventServerClick] != null){
  27. /* Got to figure out how to manage events */
  28. }
  29. base.RenderAttributes(writer);
  30. }
  31. void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(string eventArgument){
  32. if (CausesValidation){
  33. Page.Validate();
  34. }
  35. OnServerClick(EventArgs.Empty);
  36. }
  37. public event EventHandler ServerClick{
  38. add{
  39. Events.AddHandler(EventServerClick, value);
  40. }
  41. remove{
  42. Events.RemoveHandler(EventServerClick, value);
  43. }
  44. }
  45. public bool CausesValidation{
  46. get{
  47. object attr = ViewState["CausesValidation"];
  48. if (attr != null){
  49. return (Boolean) attr;
  50. }
  51. return true;
  52. }
  53. set{
  54. ViewState["CausesValidation"] = (Boolean) value;
  55. }
  56. }
  57. } // class HtmlButton
  58. } // namespace System.Web.UI.HtmlControls