HtmlInputHidden.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / HtmlControls / HtmlInputHidden.cs / 1 / HtmlInputHidden.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * HtmlInputHidden.cs 
 *
 * Copyright (c) 2000 Microsoft Corporation 
 */

namespace System.Web.UI.HtmlControls {
    using System.ComponentModel; 
    using System;
    using System.Collections; 
    using System.Collections.Specialized; 
    using System.Web;
    using System.Web.UI; 
    using System.Security.Permissions;


///  
///    
///       The  class defines the methods, properties, 
///       and events of the HtmlInputHidden control. This class allows programmatic access 
///       to the HTML <input type=hidden> element on the server.
///     
/// 
    [
    DefaultEvent("ServerChange"),
    SupportsEventValidation, 
    ]
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
    public class HtmlInputHidden : HtmlInputControl, IPostBackDataHandler {
 
        private static readonly object EventServerChange = new object();

        /*
         * Creates an intrinsic Html INPUT type=hidden control. 
         */
 
        public HtmlInputHidden() : base("hidden") { 
        }
 

        /// 
        ///    
        ///       Occurs when the  control 
        ///       is changed on the server.
        ///     
        ///  
        [
        WebCategory("Action"), 
        WebSysDescription(SR.HtmlInputHidden_OnServerChange)
        ]
        public event EventHandler ServerChange {
            add { 
                Events.AddHandler(EventServerChange, value);
            } 
            remove { 
                Events.RemoveHandler(EventServerChange, value);
            } 
        }

        /*
         * Method used to raise the OnServerChange event. 
         */
 
        ///  
        ///    
        ///       Raised on the server when the  control 
        ///       changes between postback requests.
        ///    
        /// 
        protected virtual void OnServerChange(EventArgs e) { 
            EventHandler handler = (EventHandler)Events[EventServerChange];
            if (handler != null) handler(this, e); 
        } 

        /* 
         *
         */

        ///  
        /// 
        ///  
        protected internal override void OnPreRender(EventArgs e) { 
            base.OnPreRender(e);
 
            // if no change handler, no need to save posted property
            if (!Disabled) {
                if (Events[EventServerChange] == null) {
                    ViewState.SetItemDirty("value",false); 
                }
 
                if (Page != null) { 
                    Page.RegisterEnabledControl(this);
                } 
            }
        }

        /* 
         * Method of IPostBackDataHandler interface to process posted data.
         * InputText process a newly posted value. 
         */ 

        ///  
        /// 
        /// 
        bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
            return LoadPostData(postDataKey, postCollection); 
        }
 
        protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) { 
            string current = Value;
            string text = postCollection.GetValues(postDataKey)[0]; 

            if (!current.Equals(text)) {
                ValidateEvent(postDataKey);
 
                Value = text;
                return true; 
            } 

            return false; 
        }

        protected override void RenderAttributes(HtmlTextWriter writer) {
            base.RenderAttributes(writer); 

            if (Page != null) { 
                Page.ClientScript.RegisterForEventValidation(RenderedNameAttribute); 
            }
        } 

        /*
         * Method of IPostBackDataHandler interface which is invoked whenever posted data
         * for a control has changed.  TextBox fires an OnTextChanged event. 
         */
 
        ///  
        /// 
        ///  
        void IPostBackDataHandler.RaisePostDataChangedEvent() {
            RaisePostDataChangedEvent();
        }
 

        ///  
        ///  
        /// 
        protected virtual void RaisePostDataChangedEvent() { 
            OnServerChange(EventArgs.Empty);
        }
    }
}
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK