Button.cs 3.7 KB

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