HtmlInputHidden.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. 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. #if NET_2_0
  50. ValidateEvent (postDataKey, String.Empty);
  51. #endif
  52. Value = data;
  53. return true;
  54. }
  55. return false;
  56. }
  57. void RaisePostDataChangedEventInternal ()
  58. {
  59. OnServerChange (EventArgs.Empty);
  60. }
  61. #if NET_2_0
  62. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  63. {
  64. return LoadPostDataInternal (postDataKey, postCollection);
  65. }
  66. protected virtual void RaisePostDataChangedEvent ()
  67. {
  68. RaisePostDataChangedEventInternal ();
  69. }
  70. #endif
  71. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  72. NameValueCollection postCollection)
  73. {
  74. #if NET_2_0
  75. return LoadPostData (postDataKey, postCollection);
  76. #else
  77. return LoadPostDataInternal (postDataKey, postCollection);
  78. #endif
  79. }
  80. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  81. {
  82. #if NET_2_0
  83. RaisePostDataChangedEvent ();
  84. #else
  85. RaisePostDataChangedEventInternal ();
  86. #endif
  87. }
  88. #if NET_2_0
  89. protected override void RenderAttributes (HtmlTextWriter writer)
  90. {
  91. Page page = Page;
  92. if (page != null)
  93. page.ClientScript.RegisterForEventValidation (Name);
  94. base.RenderAttributes (writer);
  95. }
  96. protected internal
  97. #else
  98. protected
  99. #endif
  100. override void OnPreRender (EventArgs e)
  101. {
  102. base.OnPreRender (e);
  103. if (Page != null && !Disabled) {
  104. Page.RegisterRequiresPostBack (this);
  105. #if NET_2_0
  106. Page.RegisterEnabledControl (this);
  107. #endif
  108. }
  109. }
  110. protected virtual void OnServerChange (EventArgs e)
  111. {
  112. EventHandler handler = (EventHandler) Events [ServerChangeEvent];
  113. if (handler != null)
  114. handler (this, e);
  115. }
  116. [WebSysDescription("")]
  117. [WebCategory("Action")]
  118. public event EventHandler ServerChange {
  119. add { Events.AddHandler (ServerChangeEvent, value); }
  120. remove { Events.RemoveHandler (ServerChangeEvent, value); }
  121. }
  122. }
  123. }