HtmlInputHidden.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2010 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. [SupportsEventValidation]
  38. public class HtmlInputHidden : HtmlInputControl, IPostBackDataHandler {
  39. static readonly object ServerChangeEvent = new object ();
  40. public HtmlInputHidden () : base ("hidden")
  41. {
  42. }
  43. bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
  44. {
  45. string data = postCollection [postDataKey];
  46. if (data != null && data != Value) {
  47. ValidateEvent (postDataKey, String.Empty);
  48. Value = data;
  49. return true;
  50. }
  51. return false;
  52. }
  53. void RaisePostDataChangedEventInternal ()
  54. {
  55. OnServerChange (EventArgs.Empty);
  56. }
  57. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  58. {
  59. return LoadPostDataInternal (postDataKey, postCollection);
  60. }
  61. protected virtual void RaisePostDataChangedEvent ()
  62. {
  63. RaisePostDataChangedEventInternal ();
  64. }
  65. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  66. NameValueCollection postCollection)
  67. {
  68. return LoadPostData (postDataKey, postCollection);
  69. }
  70. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  71. {
  72. RaisePostDataChangedEvent ();
  73. }
  74. protected override void RenderAttributes (HtmlTextWriter writer)
  75. {
  76. Page page = Page;
  77. if (page != null)
  78. page.ClientScript.RegisterForEventValidation (Name);
  79. base.RenderAttributes (writer);
  80. }
  81. protected internal override void OnPreRender (EventArgs e)
  82. {
  83. base.OnPreRender (e);
  84. Page page = Page;
  85. if (page != null && !Disabled) {
  86. page.RegisterRequiresPostBack (this);
  87. page.RegisterEnabledControl (this);
  88. }
  89. }
  90. protected virtual void OnServerChange (EventArgs e)
  91. {
  92. EventHandler handler = (EventHandler) Events [ServerChangeEvent];
  93. if (handler != null)
  94. handler (this, e);
  95. }
  96. [WebSysDescription("")]
  97. [WebCategory("Action")]
  98. public event EventHandler ServerChange {
  99. add { Events.AddHandler (ServerChangeEvent, value); }
  100. remove { Events.RemoveHandler (ServerChangeEvent, value); }
  101. }
  102. }
  103. }