Button.cs 3.7 KB

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