HtmlInputHidden.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. //
  22. // System.Web.UI.HtmlControls.HtmlInputHidden.cs
  23. //
  24. // Authors:
  25. // Jackson Harper ([email protected])
  26. //
  27. // (C) 2005 Novell, Inc.
  28. using System.ComponentModel;
  29. using System.Collections.Specialized;
  30. using System.Security.Permissions;
  31. namespace System.Web.UI.HtmlControls {
  32. // CAS
  33. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  34. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  35. // attributes
  36. [DefaultEvent ("ServerChange")]
  37. #if NET_2_0
  38. [SupportsEventValidation]
  39. #endif
  40. public class HtmlInputHidden : HtmlInputControl, IPostBackDataHandler {
  41. private static readonly object ServerChangeEvent = new object ();
  42. public HtmlInputHidden () : base ("hidden")
  43. {
  44. }
  45. bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
  46. {
  47. string data = postCollection [postDataKey];
  48. if (data != null && data != Value) {
  49. Value = data;
  50. return true;
  51. }
  52. return false;
  53. }
  54. void RaisePostDataChangedEventInternal ()
  55. {
  56. OnServerChange (EventArgs.Empty);
  57. }
  58. #if NET_2_0
  59. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  60. {
  61. return LoadPostDataInternal (postDataKey, postCollection);
  62. }
  63. protected virtual void RaisePostDataChangedEvent ()
  64. {
  65. RaisePostDataChangedEventInternal ();
  66. }
  67. #endif
  68. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  69. NameValueCollection postCollection)
  70. {
  71. #if NET_2_0
  72. return LoadPostData (postDataKey, postCollection);
  73. #else
  74. return LoadPostDataInternal (postDataKey, postCollection);
  75. #endif
  76. }
  77. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  78. {
  79. #if NET_2_0
  80. RaisePostDataChangedEvent ();
  81. #else
  82. RaisePostDataChangedEventInternal ();
  83. #endif
  84. }
  85. #if NET_2_0
  86. protected override void RenderAttributes (HtmlTextWriter writer)
  87. {
  88. if (Page != null)
  89. Page.ClientScript.RegisterForEventValidation (this.UniqueID);
  90. base.RenderAttributes (writer);
  91. }
  92. protected internal
  93. #else
  94. protected
  95. #endif
  96. override void OnPreRender (EventArgs e)
  97. {
  98. base.OnPreRender (e);
  99. if (Page != null) {
  100. Page.RegisterRequiresPostBack (this);
  101. }
  102. #if NET_2_0
  103. if (Page != null && !Disabled)
  104. Page.RegisterEnabledControl (this);
  105. #endif
  106. }
  107. protected virtual void OnServerChange (EventArgs e)
  108. {
  109. EventHandler handler = (EventHandler) Events [ServerChangeEvent];
  110. if (handler != null)
  111. handler (this, e);
  112. }
  113. [WebSysDescription("")]
  114. [WebCategory("Action")]
  115. public event EventHandler ServerChange {
  116. add { Events.AddHandler (ServerChangeEvent, value); }
  117. remove { Events.RemoveHandler (ServerChangeEvent, value); }
  118. }
  119. }
  120. }