Button.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Button
  4. *
  5. * Author: Gaurav Vaish
  6. * Contact: <[email protected]>, <[email protected]>
  7. * Status: 20%
  8. *
  9. * (C) Gaurav Vaish (2001)
  10. */
  11. using System;
  12. using System.ComponentModel;
  13. using System.Web;
  14. using System.Web.UI;
  15. namespace System.Web.UI.WebControls
  16. {
  17. public class Button : WebControl, IPostBackEventHandler
  18. {
  19. private static readonly object ClickEvent = new object();
  20. private static readonly object CommandEvent = new object();
  21. //private EventHandlerList ehList;
  22. public Button()
  23. {
  24. // TODO: Initialization
  25. }
  26. [Bindable(true)]
  27. public bool CausesValidation
  28. {
  29. get
  30. {
  31. Object cv = ViewState["CausesValidation"];
  32. if(cv!=null)
  33. return (Boolean)cv;
  34. return true;
  35. }
  36. set
  37. {
  38. //causesValidation = value;
  39. ViewState["CausesValidation"] = value;
  40. }
  41. }
  42. [Bindable(true)]
  43. public string CommandArgument
  44. {
  45. get
  46. {
  47. //return commandArgument;
  48. string ca = (string) ViewState["CommandArgument"];
  49. if(ca!=null)
  50. return ca;
  51. return String.Empty;
  52. }
  53. set
  54. {
  55. //commandArgument = value;
  56. ViewState["CommandArgument"] = value;
  57. }
  58. }
  59. public string CommandName
  60. {
  61. get
  62. {
  63. string cn = (string)ViewState["CommandName"];
  64. if(cn!=null)
  65. return cn;
  66. return String.Empty;
  67. }
  68. set
  69. {
  70. ViewState["CommandArgument"] = value;
  71. }
  72. }
  73. [
  74. Bindable(true),
  75. DefaultValueAttribute("")
  76. ]
  77. //[WebSysDescriptionAttribute("Button_Text")]
  78. //[WebCategoryAttribute("Appearance")]
  79. public string Text
  80. {
  81. get
  82. {
  83. string text = (string)ViewState["Text"];
  84. if(text!=null)
  85. return text;
  86. return String.Empty;
  87. }
  88. set
  89. {
  90. ViewState["Text"] = value;
  91. }
  92. }
  93. public event EventHandler Click
  94. {
  95. add
  96. {
  97. Events.AddHandler(ClickEvent, value);
  98. }
  99. remove
  100. {
  101. Events.RemoveHandler(ClickEvent, value);
  102. }
  103. }
  104. public event CommandEventHandler Command
  105. {
  106. add
  107. {
  108. Events.AddHandler(CommandEvent, value);
  109. }
  110. remove
  111. {
  112. Events.RemoveHandler(CommandEvent, value);
  113. }
  114. }
  115. protected virtual void OnClick(EventArgs e)
  116. {
  117. if(Events != null)
  118. {
  119. EventHandler eh = (EventHandler)(Events[ClickEvent]);
  120. if(eh!= null)
  121. eh(this,e);
  122. }
  123. }
  124. protected virtual void OnCommand(CommandEventArgs e)
  125. {
  126. if(Events != null)
  127. {
  128. EventHandler eh = (EventHandler)(Events[CommandEvent]);
  129. if(eh!= null)
  130. eh(this,e);
  131. }
  132. }
  133. public void RaisePostBackEvent(string eventArgument)
  134. {
  135. /* Will have to see what work needs to be done before I actually call OnClick
  136. * Basically I have to see what is to be done with the string argument
  137. */
  138. if(CausesValidation)
  139. {
  140. Page.Validate();
  141. OnClick(new EventArgs());
  142. OnCommand(new CommandEventArgs(CommandName, CommandArgument));
  143. }
  144. }
  145. protected override void AddAttributesToRender(HtmlTextWriter writer)
  146. {
  147. //??
  148. writer.AddAttribute(HtmlTextWriterAttribute.Type,"submit");
  149. writer.AddAttribute(HtmlTextWriterAttribute.Name,base.UniqueID);
  150. writer.AddAttribute(HtmlTextWriterAttribute.Value,Text);
  151. if(Page!=null)
  152. {
  153. if(CausesValidation)
  154. {
  155. //Page.Validators.Count
  156. //writer.AddAttribute(HtmlTextWriterAttribute.OnClick, <<The validationcode>>);
  157. writer.AddAttribute("language","javascript");
  158. }
  159. }
  160. }
  161. protected override void RenderContents(HtmlTextWriter writer)
  162. {
  163. // Preventing
  164. }
  165. }
  166. }