locked
Understanding [Serializable()] RRS feed

  • Question

  • User-1004886483 posted

    On top of my class i have this :

    [Serializable()]

    what does it mean? and what it actually does?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    
    
    [Serializable()]
    public class CheckBoxColumn : System.Web.UI.WebControls.TemplateColumn
    {
        /// <summary>
        /// Initialise our CheckBoxColumn.
        /// </summary>
        public CheckBoxColumn()
        {
            // set the view one as readonly
            viewItem = new CheckBoxItem(false); // SAW was false
            this.ItemTemplate = viewItem as ITemplate;
    
            // let the edit check box be editable
            editItem = new CheckBoxItem(true);
            this.EditItemTemplate = editItem as ITemplate;
        }
    
        /// <summary>
        /// Initialise our CheckBoxColumn with an optional ImmediatePostback capability.
        /// </summary>
        /// <param name="ImmediatePostback">If true then each change of state of the CheckBox item
        /// will cause an event to be fired immediately on the server.</param>
        public CheckBoxColumn(bool ImmediatePostback)
        {
            // set the view one as readonly
            viewItem = new CheckBoxItem(ImmediatePostback);
            this.ItemTemplate = viewItem as ITemplate;
    
            // let the edit check box be editable
            editItem = new CheckBoxItem(true);
            this.EditItemTemplate = editItem as ITemplate;
    
            AutoPostBack = ImmediatePostback;
        }
    
        /// <summary>
        /// Occurs when the value of the Checked property changes between posts to the server.
        /// </summary>
        /// <remarks>
        /// The <b>CheckedChanged</b> event is raised when the value of the Checked property changes between posts to the server.
        ///
        /// <b>Note</b> This event does not post the page back to the server unless the AutoPostBack property is set to true.
        /// <b>Note</b> The control must have viewstate enabled for the <b>CheckedChanged</b> event to work correctly.
        /// </remarks>
        public event EventHandler CheckedChanged
        {
            add
            {
                viewItem.CheckedChanged += value;
                editItem.CheckedChanged += value;
            }
            remove
            {
                viewItem.CheckedChanged -= value;
                editItem.CheckedChanged -= value;
            }
        }
    
        /// <summary>
        /// If true then then each click on a CheckBox will cause an event to be fired on the server.
        /// </summary>
        public bool AutoPostBack
        {
            set
            {
                viewItem.AutoPostBack = value;
                editItem.AutoPostBack = value;
            }
            get
            {
                return viewItem.AutoPostBack;
            }
        }
    
        /// <summary>
        /// The DataField that we wish our control to bind to.
        /// </summary>
        public string DataField
        {
            get
            {
                return viewItem.DataField;
            }
            set
            {
                viewItem.DataField = value;
                editItem.DataField = value;
            }
        }
    
        /// <summary>
        /// Internal storage of the CheckBoxItem that is to be used for the view state.
        /// </summary>
        private CheckBoxItem viewItem;
    
        /// <summary>
        /// Internal storage of the CheckBoxItem that is to be used for the edit state.
        /// </summary>
        private CheckBoxItem editItem;
    }
    Friday, December 15, 2017 10:33 AM

All replies

  • User61956409 posted

    Hi devquestionsanswers,<o:p></o:p>

    Understanding [Serializable()]

    If we apply the SerializableAttribute attribute to a type, which indicates that instances of this type can be serialized. For detailed information about SerializableAttribute attribute, please check this documentation.<o:p></o:p>

    Besides, this SO thread discussed “What is [Serializable] and when should I use it”, which would be helpful for you to understand SerializableAttribute attribute.<o:p></o:p>

    With Regards, <o:p></o:p>

    Fei Han<o:p></o:p>

    Tuesday, December 19, 2017 2:26 AM