Control

[ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DesignerSerializer("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, Microsoft.VSDesigner, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ToolboxItemFilter("System.Web.UI", ToolboxItemFilterType.Require), DefaultProperty("ID"), DesignerCategory("Code"), Designer("System.Web.UI.Design.ControlDesigner, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), PermissionSet(SecurityAction.LinkDemand, XML="<PermissionSet class=\"System.Security.PermissionSet\"\r\n               version=\"1\">\r\n   <IPermission class=\"System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n                version=\"1\"\r\n                Level=\"Minimal\"/>\r\n</PermissionSet>\r\n"), PermissionSet(SecurityAction.InheritanceDemand, XML="<PermissionSet class=\"System.Security.PermissionSet\"\r\n               version=\"1\">\r\n   <IPermission class=\"System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n                version=\"1\"\r\n                Level=\"Minimal\"/>\r\n</PermissionSet>\r\n")]
public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
{
    // Fields
    private string _cachedUniqueID;
    private ControlCollection _controls;
    private ControlState _controlState;
    private IDictionary _controlsViewState;
    private DataBindingCollection _dataBindings;
    private EventHandlerList _events;
    private string _id;
    private IDictionary _namedControls;
    private int _namedControlsID;
    private Control _namingContainer;
    internal Page _page;
    private Control _parent;
    private RenderMethod _renderMethod;
    private ISite _site;
    private StateBag _viewState;
    private const int automaticIDCount = 0x80;
    private const string automaticIDPrefix = "_ctl";
    private static readonly string[] automaticIDs = new string[] { 
        "_ctl0", "_ctl1", "_ctl2", "_ctl3", "_ctl4", "_ctl5", "_ctl6", "_ctl7", "_ctl8", "_ctl9", "_ctl10", "_ctl11", "_ctl12", "_ctl13", "_ctl14", "_ctl15", 
        "_ctl16", "_ctl17", "_ctl18", "_ctl19", "_ctl20", "_ctl21", "_ctl22", "_ctl23", "_ctl24", "_ctl25", "_ctl26", "_ctl27", "_ctl28", "_ctl29", "_ctl30", "_ctl31", 
        "_ctl32", "_ctl33", "_ctl34", "_ctl35", "_ctl36", "_ctl37", "_ctl38", "_ctl39", "_ctl40", "_ctl41", "_ctl42", "_ctl43", "_ctl44", "_ctl45", "_ctl46", "_ctl47", 
        "_ctl48", "_ctl49", "_ctl50", "_ctl51", "_ctl52", "_ctl53", "_ctl54", "_ctl55", "_ctl56", "_ctl57", "_ctl58", "_ctl59", "_ctl60", "_ctl61", "_ctl62", "_ctl63", 
        "_ctl64", "_ctl65", "_ctl66", "_ctl67", "_ctl68", "_ctl69", "_ctl70", "_ctl71", "_ctl72", "_ctl73", "_ctl74", "_ctl75", "_ctl76", "_ctl77", "_ctl78", "_ctl79", 
        "_ctl80", "_ctl81", "_ctl82", "_ctl83", "_ctl84", "_ctl85", "_ctl86", "_ctl87", "_ctl88", "_ctl89", "_ctl90", "_ctl91", "_ctl92", "_ctl93", "_ctl94", "_ctl95", 
        "_ctl96", "_ctl97", "_ctl98", "_ctl99", "_ctl100", "_ctl101", "_ctl102", "_ctl103", "_ctl104", "_ctl105", "_ctl106", "_ctl107", "_ctl108", "_ctl109", "_ctl110", "_ctl111", 
        "_ctl112", "_ctl113", "_ctl114", "_ctl115", "_ctl116", "_ctl117", "_ctl118", "_ctl119", "_ctl120", "_ctl121", "_ctl122", "_ctl123", "_ctl124", "_ctl125", "_ctl126", "_ctl127"
     };
    private const int controlsCreated = 8;
    private const int creatingControls = 0x100;
    private const int disableViewState = 4;
    private static readonly object EventDataBinding = new object();
    private static readonly object EventDisposed = new object();
    private static readonly object EventInit = new object();
    private static readonly object EventLoad = new object();
    private static readonly object EventPreRender = new object();
    private static readonly object EventUnload = new object();
    private SimpleBitVector32 flags;
    private const char ID_RENDER_SEPARATOR = '_';
    internal const char ID_SEPARATOR = ':';
    private const int idNotCalculated = 1;
    private const int idNotRequired = 0x40;
    private const int invisible = 0x10;
    private const int isNamingContainer = 0x80;
    private const int marked = 2;
    private const int nonBindingContainer = 0x200;
    private const int visibleDirty = 0x20;

    // Events
    [WebSysDescription("Control_OnDataBind"), WebCategory("Data")]
    public event EventHandler DataBinding
    {
        add
        {
            this.Events.AddHandler(EventDataBinding, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventDataBinding, value);
        }
    }

    [WebSysDescription("Control_OnDisposed")]
    public event EventHandler Disposed
    {
        add
        {
            this.Events.AddHandler(EventDisposed, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventDisposed, value);
        }
    }

    [WebSysDescription("Control_OnInit")]
    public event EventHandler Init
    {
        add
        {
            this.Events.AddHandler(EventInit, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventInit, value);
        }
    }

    [WebSysDescription("Control_OnLoad")]
    public event EventHandler Load
    {
        add
        {
            this.Events.AddHandler(EventLoad, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventLoad, value);
        }
    }

    [WebSysDescription("Control_OnPreRender")]
    public event EventHandler PreRender
    {
        add
        {
            this.Events.AddHandler(EventPreRender, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventPreRender, value);
        }
    }

    [WebSysDescription("Control_OnUnload")]
    public event EventHandler Unload
    {
        add
        {
            this.Events.AddHandler(EventUnload, value);
        }
        remove
        {
            this.Events.RemoveHandler(EventUnload, value);
        }
    }

    // Methods
    public Control()
    {
        if (this is INamingContainer)
        {
            this.flags[0x80] = true;
        }
    }

    protected internal virtual void AddedControl(Control control, int index)
    {
        if (control._parent != null)
        {
            control._parent.Controls.Remove(control);
        }
        control._parent = this;
        control._page = this._page;
        Control namingContainer = this.flags[0x80] ? this : this._namingContainer;
        if (namingContainer != null)
        {
            control._namingContainer = namingContainer;
            if ((control._id == null) && !control.flags[0x40])
            {
                control.GenerateAutomaticID();
            }
            else if ((control._id != null) || (control._controls != null))
            {
                namingContainer.DirtyNameTable();
            }
        }
        if (this._controlState >= ControlState.ChildrenInitialized)
        {
            control.InitRecursive(namingContainer);
            if (this._controlState >= ControlState.ViewStateLoaded)
            {
                object savedState = null;
                if (this._controlsViewState != null)
                {
                    savedState = this._controlsViewState[index];
                    this._controlsViewState.Remove(index);
                }
                control.LoadViewStateRecursive(savedState);
                if (this._controlState >= ControlState.Loaded)
                {
                    control.LoadRecursive();
                    if (this._controlState >= ControlState.PreRendered)
                    {
                        control.PreRenderRecursiveInternal();
                    }
                }
            }
        }
    }

    protected virtual void AddParsedSubObject(object obj)
    {
        Control child = obj as Control;
        if (child != null)
        {
            this.Controls.Add(child);
        }
    }

    protected void BuildProfileTree(string parentId, bool calcViewState)
    {
        int num;
        calcViewState = calcViewState && !this.flags[4];
        if (calcViewState)
        {
            num = LosFormatter.EstimateSize(this.SaveViewState());
        }
        else
        {
            num = 0;
        }
        this.Page.Trace.AddNewControl(this.UniqueID, parentId, base.GetType().FullName, num);
        if (this._controls != null)
        {
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].BuildProfileTree(this.UniqueID, calcViewState);
            }
        }
    }

    internal void ClearCachedUniqueIDRecursive()
    {
        this._cachedUniqueID = null;
        if (this._controls != null)
        {
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].ClearCachedUniqueIDRecursive();
            }
        }
    }

    protected void ClearChildViewState()
    {
        this._controlsViewState = null;
    }

    internal void ClearNamingContainer()
    {
        this._namedControlsID = 0;
        this.DirtyNameTable();
    }

    protected virtual void CreateChildControls()
    {
    }

    protected virtual ControlCollection CreateControlCollection()
    {
        return new ControlCollection(this);
    }

    public virtual void DataBind()
    {
        this.OnDataBinding(EventArgs.Empty);
        if (this._controls != null)
        {
            string errorMsg = this._controls.SetCollectionReadOnly("Parent_collections_readonly");
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].DataBind();
            }
            this._controls.SetCollectionReadOnly(errorMsg);
        }
    }

    internal void DirtyNameTable()
    {
        this._namedControls = null;
    }

    public virtual void Dispose()
    {
        IContainer service = null;
        if (this._site != null)
        {
            service = (IContainer) this._site.GetService(typeof(IContainer));
            if (service != null)
            {
                service.Remove(this);
                EventHandler handler = this.Events[EventDisposed] as EventHandler;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            }
        }
    }

    protected virtual void EnsureChildControls()
    {
        if (!this.ChildControlsCreated && !this.flags[0x100])
        {
            this.flags[0x100] = true;
            try
            {
                this.CreateChildControls();
            }
            finally
            {
                this.flags[0x100] = false;
                this.ChildControlsCreated = true;
            }
        }
    }

    private void EnsureNamedControlsTable()
    {
        this._namedControls = new HybridDictionary(this._namedControlsID, true);
        this.FillNamedControlsTable(this, this._controls);
    }

    private void FillNamedControlsTable(Control namingContainer, ControlCollection controls)
    {
        int count = controls.Count;
        for (int i = 0; i < count; i++)
        {
            Control control = controls[i];
            if (control._id != null)
            {
                try
                {
                    namingContainer._namedControls.Add(control._id, control);
                }
                catch (Exception)
                {
                    throw new HttpException(HttpRuntime.FormatResourceString("Duplicate_id_used", control._id, "FindControl"));
                }
            }
            if (control.HasControls() && !control.flags[0x80])
            {
                this.FillNamedControlsTable(namingContainer, control.Controls);
            }
        }
    }

    public virtual Control FindControl(string id)
    {
        return this.FindControl(id, 0);
    }

    protected virtual Control FindControl(string id, int pathOffset)
    {
        string str;
        this.EnsureChildControls();
        if (!this.flags[0x80])
        {
            Control namingContainer = this.NamingContainer;
            if (namingContainer != null)
            {
                return namingContainer.FindControl(id, pathOffset);
            }
            return null;
        }
        if ((this._namedControls == null) && this.HasControls())
        {
            this.EnsureNamedControlsTable();
        }
        if (this._namedControls == null)
        {
            return null;
        }
        int index = id.IndexOf(':', pathOffset);
        if (index == -1)
        {
            str = id.Substring(pathOffset);
            return (this._namedControls[str] as Control);
        }
        str = id.Substring(pathOffset, index - pathOffset);
        Control control2 = this._namedControls[str] as Control;
        if (control2 == null)
        {
            return null;
        }
        return control2.FindControl(id, index + 1);
    }

    private void GenerateAutomaticID()
    {
        int index = this._namingContainer._namedControlsID++;
        if (index < 0x80)
        {
            this._id = automaticIDs[index];
        }
        else
        {
            this._id = "_ctl" + index.ToString(NumberFormatInfo.InvariantInfo);
        }
        this._namingContainer.DirtyNameTable();
    }

    internal virtual string GetUniqueIDPrefix()
    {
        string uniqueID = this.UniqueID;
        if ((uniqueID != null) && (uniqueID.Length > 0))
        {
            char ch = ':';
            return (uniqueID + ch.ToString());
        }
        return "";
    }

    public virtual bool HasControls()
    {
        return ((this._controls != null) && (this._controls.Count > 0));
    }

    internal bool HasRenderingData()
    {
        if (!this.HasControls())
        {
            return (this._renderMethod != null);
        }
        return true;
    }

    internal void InitRecursive(Control namingContainer)
    {
        if (this._controls != null)
        {
            if (this.flags[0x80])
            {
                namingContainer = this;
            }
            string errorMsg = this._controls.SetCollectionReadOnly("Parent_collections_readonly");
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                Control control = this._controls[i];
                control._namingContainer = namingContainer;
                if (((namingContainer != null) && (control._id == null)) && !control.flags[0x40])
                {
                    control.GenerateAutomaticID();
                }
                control._page = this._page;
                control.InitRecursive(namingContainer);
            }
            this._controls.SetCollectionReadOnly(errorMsg);
        }
        if (this._controlState < ControlState.Initialized)
        {
            this._controlState = ControlState.ChildrenInitialized;
            this.OnInit(EventArgs.Empty);
            this._controlState = ControlState.Initialized;
        }
        this.TrackViewState();
    }

    internal bool IsDescendentOf(Control ancestor)
    {
        if (this == ancestor)
        {
            return true;
        }
        if (this._parent == null)
        {
            return false;
        }
        return this._parent.IsDescendentOf(ancestor);
    }

    protected bool IsLiteralContent()
    {
        return (((this._controls != null) && (this._controls.Count == 1)) && (this._controls[0] is LiteralControl));
    }

    internal void LoadRecursive()
    {
        if (this._controlState < ControlState.Loaded)
        {
            this.OnLoad(EventArgs.Empty);
        }
        if (this._controls != null)
        {
            string errorMsg = this._controls.SetCollectionReadOnly("Parent_collections_readonly");
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].LoadRecursive();
            }
            this._controls.SetCollectionReadOnly(errorMsg);
        }
        if (this._controlState < ControlState.Loaded)
        {
            this._controlState = ControlState.Loaded;
        }
    }

    protected virtual void LoadViewState(object savedState)
    {
        if (savedState != null)
        {
            this.ViewState.LoadViewState(savedState);
            object obj2 = this.ViewState["Visible"];
            if (obj2 != null)
            {
                this.flags[0x10] = !((bool) obj2);
                this.flags[0x20] = true;
            }
        }
    }

    internal void LoadViewStateRecursive(object savedState)
    {
        if ((savedState != null) && !this.flags[4])
        {
            Triplet triplet = (Triplet) savedState;
            if ((this.Page != null) && this.Page.IsPostBack)
            {
                try
                {
                    this.LoadViewState(triplet.First);
                }
                catch (InvalidCastException)
                {
                    throw new HttpException(HttpRuntime.FormatResourceString("Controls_Cant_Change_Between_Posts"));
                }
                catch (IndexOutOfRangeException)
                {
                    throw new HttpException(HttpRuntime.FormatResourceString("Controls_Cant_Change_Between_Posts"));
                }
            }
            if (triplet.Second != null)
            {
                ArrayList second = (ArrayList) triplet.Second;
                ArrayList third = (ArrayList) triplet.Third;
                ControlCollection controls = this.Controls;
                int count = controls.Count;
                int num2 = second.Count;
                for (int i = 0; i < num2; i++)
                {
                    int num4 = (int) second[i];
                    if (num4 < count)
                    {
                        controls[num4].LoadViewStateRecursive(third[i]);
                    }
                    else
                    {
                        if (this._controlsViewState == null)
                        {
                            this._controlsViewState = new Hashtable();
                        }
                        this._controlsViewState[num4] = third[i];
                    }
                }
            }
            this._controlState = ControlState.ViewStateLoaded;
        }
    }

    protected string MapPathSecure(string virtualPath)
    {
        string str = UrlPath.Combine(this.TemplateSourceDirectory, virtualPath);
        string path = this.Context.Request.MapPath(str);
        if (!HttpRuntime.HasFilePermission(path))
        {
            throw new HttpException(HttpRuntime.FormatResourceString("Access_denied_to_vpath", virtualPath));
        }
        return path;
    }

    protected virtual bool OnBubbleEvent(object source, EventArgs args)
    {
        return false;
    }

    protected virtual void OnDataBinding(EventArgs e)
    {
        if (this._events != null)
        {
            EventHandler handler = this._events[EventDataBinding] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    protected virtual void OnInit(EventArgs e)
    {
        if (this._events != null)
        {
            EventHandler handler = this._events[EventInit] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    protected virtual void OnLoad(EventArgs e)
    {
        if (this._events != null)
        {
            EventHandler handler = this._events[EventLoad] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    protected virtual void OnPreRender(EventArgs e)
    {
        if (this._events != null)
        {
            EventHandler handler = this._events[EventPreRender] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    protected virtual void OnUnload(EventArgs e)
    {
        if (this._events != null)
        {
            EventHandler handler = this._events[EventUnload] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    internal void PreRenderRecursiveInternal()
    {
        if (!this.flags[0x10])
        {
            this.EnsureChildControls();
            this.OnPreRender(EventArgs.Empty);
            if (this._controls != null)
            {
                string errorMsg = this._controls.SetCollectionReadOnly("Parent_collections_readonly");
                int count = this._controls.Count;
                for (int i = 0; i < count; i++)
                {
                    this._controls[i].PreRenderRecursiveInternal();
                }
                this._controls.SetCollectionReadOnly(errorMsg);
            }
        }
        this._controlState = ControlState.PreRendered;
    }

    internal void PreventAutoID()
    {
        if (!this.flags[0x80])
        {
            this.flags[0x40] = true;
        }
    }

    protected void RaiseBubbleEvent(object source, EventArgs args)
    {
        for (Control control = this._parent; control != null; control = control.Parent)
        {
            if (control.OnBubbleEvent(source, args))
            {
                return;
            }
        }
    }

    protected internal virtual void RemovedControl(Control control)
    {
        if ((this._namingContainer != null) && (control._id != null))
        {
            this._namingContainer.DirtyNameTable();
        }
        control.UnloadRecursive(false);
        control._parent = null;
        control._page = null;
        control._namingContainer = null;
        control.ClearCachedUniqueIDRecursive();
    }

    protected virtual void Render(HtmlTextWriter writer)
    {
        this.RenderChildren(writer);
    }

    protected virtual void RenderChildren(HtmlTextWriter writer)
    {
        if (this._renderMethod != null)
        {
            this._renderMethod(writer, this);
        }
        else if (this._controls != null)
        {
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].RenderControl(writer);
            }
        }
    }

    public void RenderControl(HtmlTextWriter writer)
    {
        if (!this.flags[0x10])
        {
            HttpContext context = (this._page == null) ? null : this._page._context;
            if ((context != null) && context.TraceIsEnabled)
            {
                int bufferedLength = context.Response.GetBufferedLength();
                this.Render(writer);
                int num2 = context.Response.GetBufferedLength();
                context.Trace.AddControlSize(this.UniqueID, num2 - bufferedLength);
            }
            else
            {
                this.Render(writer);
            }
        }
    }

    internal string ResolveClientUrl(string relativeUrl)
    {
        if (relativeUrl == null)
        {
            throw new ArgumentNullException("relativeUrl");
        }
        string templateSourceDirectory = this.TemplateSourceDirectory;
        if (templateSourceDirectory.Length == 0)
        {
            return relativeUrl;
        }
        string baseDir = this.Context.Request.BaseDir;
        if (!UrlPath.IsAppRelativePath(relativeUrl))
        {
            if (string.Compare(baseDir, templateSourceDirectory, true, CultureInfo.InvariantCulture) == 0)
            {
                return relativeUrl;
            }
            if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
            {
                return relativeUrl;
            }
        }
        string to = UrlPath.Combine(templateSourceDirectory, relativeUrl);
        return UrlPath.MakeRelative(UrlPath.AppendSlashToPathIfNeeded(baseDir), to);
    }

    public string ResolveUrl(string relativeUrl)
    {
        if (relativeUrl == null)
        {
            throw new ArgumentNullException("relativeUrl");
        }
        if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
        {
            return relativeUrl;
        }
        string templateSourceDirectory = this.TemplateSourceDirectory;
        if (templateSourceDirectory.Length == 0)
        {
            return relativeUrl;
        }
        string virtualPath = UrlPath.Combine(templateSourceDirectory, relativeUrl);
        return this.Context.Response.ApplyAppPathModifier(virtualPath);
    }

    protected virtual object SaveViewState()
    {
        if (this.flags[0x20])
        {
            this.ViewState["Visible"] = !this.flags[0x10];
        }
        if (this._viewState != null)
        {
            return this._viewState.SaveViewState();
        }
        return null;
    }

    internal object SaveViewStateRecursive()
    {
        if (this.flags[4])
        {
            return null;
        }
        object x = this.SaveViewState();
        ArrayList y = null;
        ArrayList z = null;
        if (this._controls != null)
        {
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                object obj3 = this._controls[i].SaveViewStateRecursive();
                if (obj3 != null)
                {
                    if (y == null)
                    {
                        y = new ArrayList();
                        z = new ArrayList();
                    }
                    y.Add(i);
                    z.Add(obj3);
                }
            }
        }
        Triplet triplet = null;
        if ((x == null) && (y == null))
        {
            return triplet;
        }
        return new Triplet(x, y, z);
    }

    internal void SetNonBindingContainer()
    {
        this.flags[0x200] = true;
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    public void SetRenderMethodDelegate(RenderMethod renderMethod)
    {
        this._renderMethod = renderMethod;
        this.Controls.SetCollectionReadOnly("Collection_readonly_Codeblocks");
    }

    void IParserAccessor.AddParsedSubObject(object obj)
    {
        this.AddParsedSubObject(obj);
    }

    protected virtual void TrackViewState()
    {
        if (this._viewState != null)
        {
            this._viewState.TrackViewState();
        }
        this.flags[2] = true;
    }

    internal void UnloadRecursive(bool dispose)
    {
        if (this._controls != null)
        {
            string errorMsg = this._controls.SetCollectionReadOnly("Parent_collections_readonly");
            int count = this._controls.Count;
            for (int i = 0; i < count; i++)
            {
                this._controls[i].UnloadRecursive(dispose);
            }
            this._controls.SetCollectionReadOnly(errorMsg);
        }
        this.OnUnload(EventArgs.Empty);
        if (dispose)
        {
            this.Dispose();
        }
        if (this.IsReloadable)
        {
            this._controlState = ControlState.Constructed;
        }
    }

    // Properties
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
    public Control BindingContainer
    {
        get
        {
            Control namingContainer = this.NamingContainer;
            if (namingContainer.flags[0x200])
            {
                namingContainer = namingContainer.BindingContainer;
            }
            return namingContainer;
        }
    }

    protected bool ChildControlsCreated
    {
        get
        {
            return this.flags[8];
        }
        set
        {
            if (!value && this.flags[8])
            {
                this.Controls.Clear();
            }
            this.flags[8] = value;
        }
    }

    [Browsable(false), WebSysDescription("Control_ClientID"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public virtual string ClientID
    {
        get
        {
            string uniqueID = this.UniqueID;
            if (this.UniqueID == null)
            {
                return null;
            }
            if (uniqueID.IndexOf(':') >= 0)
            {
                return uniqueID.Replace(':', '_');
            }
            return uniqueID;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
    protected virtual HttpContext Context
    {
        get
        {
            if (this._page != null)
            {
                return this._page.Context;
            }
            return HttpContext.Current;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Control_Controls")]
    public virtual ControlCollection Controls
    {
        get
        {
            if (this._controls == null)
            {
                this._controls = this.CreateControlCollection();
            }
            return this._controls;
        }
    }

    internal ControlState ControlState
    {
        get
        {
            return this._controlState;
        }
    }

    [WebSysDescription("Control_MaintainState"), DefaultValue(true), WebCategory("Behavior")]
    public virtual bool EnableViewState
    {
        get
        {
            return !this.flags[4];
        }
        set
        {
            this.flags[4] = !value;
        }
    }

    protected EventHandlerList Events
    {
        get
        {
            if (this._events == null)
            {
                this._events = new EventHandlerList();
            }
            return this._events;
        }
    }

    protected bool HasChildViewState
    {
        get
        {
            return ((this._controlsViewState != null) && (this._controlsViewState.Count > 0));
        }
    }

    [MergableProperty(false), ParenthesizePropertyName(true), WebSysDescription("Control_ID")]
    public virtual string ID
    {
        get
        {
            if (!this.flags[1])
            {
                return null;
            }
            return this._id;
        }
        set
        {
            if ((value != null) && (value.Length == 0))
            {
                value = null;
            }
            string str = this._id;
            this._id = value;
            this.ClearCachedUniqueIDRecursive();
            this.flags[1] = true;
            if ((this._namingContainer != null) && (str != null))
            {
                this._namingContainer.DirtyNameTable();
            }
        }
    }

    internal virtual bool IsReloadable
    {
        get
        {
            return false;
        }
    }

    protected bool IsTrackingViewState
    {
        get
        {
            return this.flags[2];
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_NamingContainer"), Browsable(false)]
    public virtual Control NamingContainer
    {
        get
        {
            if ((this._namingContainer == null) && (this._parent != null))
            {
                if (this._parent.flags[0x80])
                {
                    this._namingContainer = this._parent;
                }
                else
                {
                    this._namingContainer = this._parent.NamingContainer;
                }
            }
            return this._namingContainer;
        }
    }

    [Browsable(false), WebSysDescription("Control_Page"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public virtual Page Page
    {
        get
        {
            if ((this._page == null) && (this._parent != null))
            {
                this._page = this._parent.Page;
            }
            return this._page;
        }
        set
        {
            this._page = value;
        }
    }

    [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_Parent")]
    public virtual Control Parent
    {
        get
        {
            return this._parent;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced), WebSysDescription("Control_Site")]
    public ISite Site
    {
        get
        {
            return this._site;
        }
        set
        {
            this._site = value;
        }
    }

    DataBindingCollection IDataBindingsAccessor.DataBindings
    {
        get
        {
            if (this._dataBindings == null)
            {
                this._dataBindings = new DataBindingCollection();
            }
            return this._dataBindings;
        }
    }

    bool IDataBindingsAccessor.HasDataBindings
    {
        get
        {
            return ((this._dataBindings != null) && (this._dataBindings.Count != 0));
        }
    }

    [Browsable(false), WebSysDescription("Control_TemplateSourceDirectory"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public virtual string TemplateSourceDirectory
    {
        get
        {
            if (this._parent == null)
            {
                return string.Empty;
            }
            return this._parent.TemplateSourceDirectory;
        }
    }

    [WebSysDescription("Control_UniqueID"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
    public virtual string UniqueID
    {
        get
        {
            if (this._cachedUniqueID == null)
            {
                if (this._namingContainer == null)
                {
                    return this._id;
                }
                if (this._id == null)
                {
                    this.GenerateAutomaticID();
                }
                if (this._page == this._namingContainer)
                {
                    this._cachedUniqueID = this._id;
                }
                else
                {
                    if (this._namingContainer.GetUniqueIDPrefix().Length == 0)
                    {
                        return this._id;
                    }
                    this._cachedUniqueID = this._namingContainer.GetUniqueIDPrefix() + this._id;
                }
            }
            return this._cachedUniqueID;
        }
    }

    internal string UniqueIDWithDollars
    {
        get
        {
            string uniqueID = this.UniqueID;
            if (uniqueID == null)
            {
                return null;
            }
            if (uniqueID.IndexOf(':') >= 0)
            {
                return uniqueID.Replace(':', '$');
            }
            return uniqueID;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_State"), Browsable(false)]
    protected virtual StateBag ViewState
    {
        get
        {
            if (this._viewState == null)
            {
                this._viewState = new StateBag(this.ViewStateIgnoresCase);
                if (this.IsTrackingViewState)
                {
                    this._viewState.TrackViewState();
                }
            }
            return this._viewState;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
    protected virtual bool ViewStateIgnoresCase
    {
        get
        {
            return false;
        }
    }

    [WebSysDescription("Control_Visible"), DefaultValue(true), Bindable(true), WebCategory("Behavior")]
    public virtual bool Visible
    {
        get
        {
            if (this.flags[0x10])
            {
                return false;
            }
            if (this._parent != null)
            {
                return this._parent.Visible;
            }
            return true;
        }
        set
        {
            bool flag = !this.flags[0x10];
            if (flag != value)
            {
                this.flags[0x10] = !value;
                if (this.flags[2])
                {
                    this.flags[0x20] = true;
                }
            }
        }
    }
}
Collapse Methods

posted on 2010-02-22 10:04  木可  阅读(515)  评论(1编辑  收藏  举报

导航