Command.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * Project : Mono
  3. * Namespace : System.Web.UI.MobileControls
  4. * Class : Command
  5. * Author : Gaurav Vaish
  6. *
  7. * Copyright : 2003 with Gaurav Vaish, and with
  8. * Ximian Inc
  9. */
  10. using System.Collections.Specialized;
  11. using System.Web.UI;
  12. using System.Web.UI.WebControls;
  13. namespace System.Web.UI.MobileControls
  14. {
  15. public class Command : TextControl, IPostBackEventHandler,
  16. IPostBackDataHandler
  17. {
  18. private static readonly object ClickEvent = new object();
  19. private static readonly object ItemCommandEvent = new object();
  20. public Command()
  21. {
  22. }
  23. public event EventHandler Click
  24. {
  25. add
  26. {
  27. Events.AddHandler(ClickEvent, value);
  28. }
  29. remove
  30. {
  31. Events.RemoveHandler(ClickEvent, value);
  32. }
  33. }
  34. public event ObjectListCommandEventHandler ItemCommand
  35. {
  36. add
  37. {
  38. Events.AddHandler(ItemCommandEvent, value);
  39. }
  40. remove
  41. {
  42. Events.RemoveHandler(ItemCommandEvent, value);
  43. }
  44. }
  45. bool IPostBackDataHandler.LoadPostData(string key,
  46. NameValueCollection data)
  47. {
  48. bool dataChanged;
  49. bool stateChanged = Adapter.LoadPostData(key, data, null, out dataChanged);
  50. if(stateChanged)
  51. {
  52. if(dataChanged)
  53. Page.RegisterRequiresRaiseEvent(this);
  54. } else
  55. {
  56. if(data[key] != null)
  57. Page.RegisterRequiresRaiseEvent(this);
  58. }
  59. return false;
  60. }
  61. void IPostBackDataHandler.RaisePostDataChangedEvent()
  62. {
  63. }
  64. void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
  65. {
  66. if(CausesValidation)
  67. MobilePage.Validate();
  68. Form.CurrentPage = 1;
  69. OnClick(EventArgs.Empty);
  70. OnItemCommand(new CommandEventArgs(CommandName, CommandArgument));
  71. }
  72. public bool CausesValidation
  73. {
  74. get
  75. {
  76. object o = ViewState["CausesValidation"];
  77. if(o != null)
  78. return (bool)o;
  79. return true;
  80. }
  81. set
  82. {
  83. ViewState["CausesValidation"] = value;
  84. }
  85. }
  86. public string CommandArgument
  87. {
  88. get
  89. {
  90. object o = ViewState["CommandArgument"];
  91. if(o != null)
  92. return (string)o;
  93. return String.Empty;
  94. }
  95. set
  96. {
  97. ViewState["CommandArgument"] = value;
  98. }
  99. }
  100. public string CommandName
  101. {
  102. get
  103. {
  104. object o = ViewState["CommandName"];
  105. if(o != null)
  106. return (string)o;
  107. return String.Empty;
  108. }
  109. set
  110. {
  111. ViewState["CommandName"] = value;
  112. }
  113. }
  114. public CommandFormat Format
  115. {
  116. get
  117. {
  118. object o = ViewState["Format"];
  119. if(o != null)
  120. return (CommandFormat)o;
  121. return CommandFormat.Button;
  122. }
  123. set
  124. {
  125. //if(!System.Enum.IsDefined(typeof(CommandFormat), value)
  126. // throw new ArgumentException("Illegal value");
  127. ViewState["Format"] = value;
  128. }
  129. }
  130. public string ImageUrl
  131. {
  132. get
  133. {
  134. object o = ViewState["ImageUrl"];
  135. if(o != null)
  136. return (string)o;
  137. return String.Empty;
  138. }
  139. set
  140. {
  141. ViewState["ImageUrl"] = value;
  142. }
  143. }
  144. public string SoftKeyLabel
  145. {
  146. get
  147. {
  148. object o = ViewState["SoftKeyLabel"];
  149. if(o != null)
  150. return (string)o;
  151. return String.Empty;
  152. }
  153. set
  154. {
  155. ViewState["SoftKeyLabel"] = value;
  156. }
  157. }
  158. protected virtual void OnClick(EventArgs e)
  159. {
  160. EventHandler eh = (EventHandler)(Events[ClickEvent]);
  161. if(eh != null)
  162. eh(this, e);
  163. }
  164. protected virtual void OnItemCommand(CommandEventArgs e)
  165. {
  166. CommandEventHandler ceh = (CommandEventHandler)(Events[ItemCommandEvent]);
  167. if(ceh != null)
  168. ceh(this, e);
  169. }
  170. protected virtual bool IsFormSubmitControl()
  171. {
  172. return true;
  173. }
  174. }
  175. }