最近做项目,脑子发热想全用代码实现,就开始了服务器控件的探索,凭借一点点书上看来的东西,其它不说,先贴上几个常用控件反编译后的代码。
[SupportsEventValidation, DefaultProperty("Text"), ToolboxData("<{0}:Button runat=\"server\" Text=\"Button\"></{0}:Button>"), DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), Designer("System.Web.UI.Design.WebControls.ButtonDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DefaultEvent("Click"), AspNetHostingPermission(SecurityAction.LinkDemand, Level=200), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=200)]
public class Button : WebControl, IButtonControl, IPostBackEventHandler
{
// Fields
private static readonly object EventClick = new object();
private static readonly object EventCommand = new object();
// Events
[WebCategory("Action"), WebSysDescription("Button_OnClick")]
public event EventHandler Click
{
add
{
base.Events.AddHandler(EventClick, value);
}
remove
{
base.Events.RemoveHandler(EventClick, value);
}
}
[WebCategory("Action"), WebSysDescription("Button_OnCommand")]
public event CommandEventHandler Command
{
add
{
base.Events.AddHandler(EventCommand, value);
}
remove
{
base.Events.RemoveHandler(EventCommand, value);
}
}
// Methods
public Button() : base(HtmlTextWriterTag.Input)
{
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
bool useSubmitBehavior = this.UseSubmitBehavior;
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
if (useSubmitBehavior)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "submit");
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
}
PostBackOptions postBackOptions = this.GetPostBackOptions();
string uniqueID = this.UniqueID;
if ((uniqueID != null) && ((postBackOptions == null) || (postBackOptions.TargetControl == this)))
{
writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
}
writer.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
bool isEnabled = base.IsEnabled;
string firstScript = string.Empty;
if (isEnabled)
{
firstScript = Util.EnsureEndWithSemiColon(this.OnClientClick);
if (base.HasAttributes)
{
string str3 = base.Attributes["onclick"];
if (str3 != null)
{
firstScript = firstScript + Util.EnsureEndWithSemiColon(str3);
base.Attributes.Remove("onclick");
}
}
if (this.Page != null)
{
string postBackEventReference = this.Page.ClientScript.GetPostBackEventReference(postBackOptions, false);
if (postBackEventReference != null)
{
firstScript = Util.MergeScript(firstScript, postBackEventReference);
}
}
}
if (this.Page != null)
{
this.Page.ClientScript.RegisterForEventValidation(postBackOptions);
}
if (firstScript.Length > 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, firstScript);
if (base.EnableLegacyRendering)
{
writer.AddAttribute("language", "javascript", false);
}
}
if (this.Enabled && !isEnabled)
{
writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
}
base.AddAttributesToRender(writer);
}
protected virtual PostBackOptions GetPostBackOptions()
{
PostBackOptions options = new PostBackOptions(this, string.Empty);
options.ClientSubmit = false;
if (this.Page != null)
{
if (this.CausesValidation && (this.Page.GetValidators(this.ValidationGroup).Count > 0))
{
options.PerformValidation = true;
options.ValidationGroup = this.ValidationGroup;
}
if (!string.IsNullOrEmpty(this.PostBackUrl))
{
options.ActionUrl = HttpUtility.UrlPathEncode(base.ResolveClientUrl(this.PostBackUrl));
}
options.ClientSubmit = !this.UseSubmitBehavior;
}
return options;
}
protected virtual void OnClick(EventArgs e)
{
EventHandler handler = (EventHandler) base.Events[EventClick];
if (handler != null)
{
handler(this, e);
}
}
protected virtual void OnCommand(CommandEventArgs e)
{
CommandEventHandler handler = (CommandEventHandler) base.Events[EventCommand];
if (handler != null)
{
handler(this, e);
}
base.RaiseBubbleEvent(this, e);
}
protected internal override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if ((this.Page != null) && base.IsEnabled)
{
if ((this.CausesValidation && (this.Page.GetValidators(this.ValidationGroup).Count > 0)) || !string.IsNullOrEmpty(this.PostBackUrl))
{
this.Page.RegisterWebFormsScript();
}
else if (!this.UseSubmitBehavior)
{
this.Page.RegisterPostBackScript();
}
}
}
protected virtual void RaisePostBackEvent(string eventArgument)
{
base.ValidateEvent(this.UniqueID, eventArgument);
if (this.CausesValidation)
{
this.Page.Validate(this.ValidationGroup);
}
this.OnClick(EventArgs.Empty);
this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument));
}
protected internal override void RenderContents(HtmlTextWriter writer)
{
}
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
this.RaisePostBackEvent(eventArgument);
}
// Properties
[WebSysDescription("Button_CausesValidation"), WebCategory("Behavior"), DefaultValue(true), Themeable(false)]
public virtual bool CausesValidation
{
get
{
object obj2 = this.ViewState["CausesValidation"];
if (obj2 != null)
{
return (bool) obj2;
}
return true;
}
set
{
this.ViewState["CausesValidation"] = value;
}
}
[Bindable(true), DefaultValue(""), Themeable(false), WebCategory("Behavior"), WebSysDescription("WebControl_CommandArgument")]
public string CommandArgument
{
get
{
string str = (string) this.ViewState["CommandArgument"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["CommandArgument"] = value;
}
}
[Themeable(false), WebCategory("Behavior"), WebSysDescription("WebControl_CommandName"), DefaultValue("")]
public string CommandName
{
get
{
string str = (string) this.ViewState["CommandName"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["CommandName"] = value;
}
}
[Themeable(false), WebSysDescription("Button_OnClientClick"), DefaultValue(""), WebCategory("Behavior")]
public virtual string OnClientClick
{
get
{
string str = (string) this.ViewState["OnClientClick"];
if (str == null)
{
return string.Empty;
}
return str;
}
set
{
this.ViewState["OnClientClick"] = value;
}
}
[DefaultValue(""), WebCategory("Behavior"), WebSysDescription("Button_PostBackUrl"), Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), Themeable(false), UrlProperty("*.aspx")]
public virtual string PostBackUrl
{
get
{
string str = (string) this.ViewState["PostBackUrl"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["PostBackUrl"] = value;
}
}
[WebSysDescription("Button_Text"), WebCategory("Appearance"), DefaultValue(""), Localizable(true), Bindable(true)]
public string Text
{
get
{
string str = (string) this.ViewState["Text"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["Text"] = value;
}
}
[WebSysDescription("Button_UseSubmitBehavior"), WebCategory("Behavior"), DefaultValue(true), Themeable(false)]
public virtual bool UseSubmitBehavior
{
get
{
object obj2 = this.ViewState["UseSubmitBehavior"];
if (obj2 != null)
{
return (bool) obj2;
}
return true;
}
set
{
this.ViewState["UseSubmitBehavior"] = value;
}
}
[WebSysDescription("PostBackControl_ValidationGroup"), WebCategory("Behavior"), DefaultValue(""), Themeable(false)]
public virtual string ValidationGroup
{
get
{
string str = (string) this.ViewState["ValidationGroup"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["ValidationGroup"] = value;
}
}
}
Collapse Methods
[ParseChildren(true), PersistChildren(false), Themeable(true), AspNetHostingPermission(SecurityAction.LinkDemand, Level=200), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=200)]
public class WebControl : Control, IAttributeAccessor
{
// Fields
private SimpleBitVector32 _webControlFlags;
private const int accessKeySet = 4;
private AttributeCollection attrColl;
private StateBag attrState;
private Style controlStyle;
private const int deferStyleLoadViewState = 1;
private const int disabledDirty = 2;
private const int tabIndexSet = 0x10;
private HtmlTextWriterTag tagKey;
private string tagName;
private const int toolTipSet = 8;
// Methods
protected WebControl() : this(HtmlTextWriterTag.Span)
{
}
protected WebControl(string tag)
{
this.tagKey = HtmlTextWriterTag.Unknown;
this.tagName = tag;
}
public WebControl(HtmlTextWriterTag tag)
{
this.tagKey = tag;
}
protected virtual void AddAttributesToRender(HtmlTextWriter writer)
{
if (this.ID != null)
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
}
if (this._webControlFlags[4])
{
string accessKey = this.AccessKey;
if (accessKey.Length > 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, accessKey);
}
}
if (!this.Enabled)
{
writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
}
if (this._webControlFlags[0x10])
{
int tabIndex = this.TabIndex;
if (tabIndex != 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, tabIndex.ToString(NumberFormatInfo.InvariantInfo));
}
}
if (this._webControlFlags[8])
{
string toolTip = this.ToolTip;
if (toolTip.Length > 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip);
}
}
if ((this.TagKey == HtmlTextWriterTag.Span) || (this.TagKey == HtmlTextWriterTag.A))
{
this.AddDisplayInlineBlockIfNeeded(writer);
}
if (this.ControlStyleCreated && !this.ControlStyle.IsEmpty)
{
this.ControlStyle.AddAttributesToRender(writer, this);
}
if (this.attrState != null)
{
AttributeCollection attributes = this.Attributes;
IEnumerator enumerator = attributes.Keys.GetEnumerator();
while (enumerator.MoveNext())
{
string current = (string) enumerator.Current;
writer.AddAttribute(current, attributes[current]);
}
}
}
internal void AddDisplayInlineBlockIfNeeded(HtmlTextWriter writer)
{
if ((!this.RequiresLegacyRendering || !base.EnableLegacyRendering) && (((this.BorderStyle != BorderStyle.NotSet) || !this.BorderWidth.IsEmpty) || (!this.Height.IsEmpty || !this.Width.IsEmpty)))
{
writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "inline-block");
}
}
public void ApplyStyle(Style s)
{
if ((s != null) && !s.IsEmpty)
{
this.ControlStyle.CopyFrom(s);
}
}
public void CopyBaseAttributes(WebControl controlSrc)
{
if (controlSrc == null)
{
throw new ArgumentNullException("controlSrc");
}
if (controlSrc._webControlFlags[4])
{
this.AccessKey = controlSrc.AccessKey;
}
if (!controlSrc.Enabled)
{
this.Enabled = false;
}
if (controlSrc._webControlFlags[8])
{
this.ToolTip = controlSrc.ToolTip;
}
if (controlSrc._webControlFlags[0x10])
{
this.TabIndex = controlSrc.TabIndex;
}
if (controlSrc.HasAttributes)
{
foreach (string str in controlSrc.Attributes.Keys)
{
this.Attributes[str] = controlSrc.Attributes[str];
}
}
}
protected virtual Style CreateControlStyle()
{
return new Style(this.ViewState);
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
Pair pair = (Pair) savedState;
base.LoadViewState(pair.First);
if (this.ControlStyleCreated || (this.ViewState["_!SB"] != null))
{
this.ControlStyle.LoadViewState(null);
}
else
{
this._webControlFlags.Set(1);
}
if (pair.Second != null)
{
if (this.attrState == null)
{
this.attrState = new StateBag(true);
this.attrState.TrackViewState();
}
this.attrState.LoadViewState(pair.Second);
}
}
object obj2 = this.ViewState["Enabled"];
if (obj2 != null)
{
if (!((bool) obj2))
{
this.flags.Set(0x80000);
}
else
{
this.flags.Clear(0x80000);
}
this._webControlFlags.Set(2);
}
if (((IDictionary) this.ViewState).Contains("AccessKey"))
{
this._webControlFlags.Set(4);
}
if (((IDictionary) this.ViewState).Contains("TabIndex"))
{
this._webControlFlags.Set(0x10);
}
if (((IDictionary) this.ViewState).Contains("ToolTip"))
{
this._webControlFlags.Set(8);
}
}
public void MergeStyle(Style s)
{
if ((s != null) && !s.IsEmpty)
{
this.ControlStyle.MergeWith(s);
}
}
protected internal override void Render(HtmlTextWriter writer)
{
this.RenderBeginTag(writer);
this.RenderContents(writer);
this.RenderEndTag(writer);
}
public virtual void RenderBeginTag(HtmlTextWriter writer)
{
this.AddAttributesToRender(writer);
HtmlTextWriterTag tagKey = this.TagKey;
if (tagKey != HtmlTextWriterTag.Unknown)
{
writer.RenderBeginTag(tagKey);
}
else
{
writer.RenderBeginTag(this.TagName);
}
}
protected internal virtual void RenderContents(HtmlTextWriter writer)
{
base.Render(writer);
}
public virtual void RenderEndTag(HtmlTextWriter writer)
{
writer.RenderEndTag();
}
protected override object SaveViewState()
{
Pair pair = null;
if (this._webControlFlags[2])
{
this.ViewState["Enabled"] = !this.flags[0x80000];
}
if (this.ControlStyleCreated)
{
this.ControlStyle.SaveViewState();
}
object x = base.SaveViewState();
object y = null;
if (this.attrState != null)
{
y = this.attrState.SaveViewState();
}
if ((x == null) && (y == null))
{
return pair;
}
return new Pair(x, y);
}
string IAttributeAccessor.GetAttribute(string name)
{
if (this.attrState == null)
{
return null;
}
return (string) this.attrState[name];
}
void IAttributeAccessor.SetAttribute(string name, string value)
{
this.Attributes[name] = value;
}
protected override void TrackViewState()
{
base.TrackViewState();
if (this.ControlStyleCreated)
{
this.ControlStyle.TrackViewState();
}
if (this.attrState != null)
{
this.attrState.TrackViewState();
}
}
// Properties
[DefaultValue(""), WebCategory("Accessibility"), WebSysDescription("WebControl_AccessKey")]
public virtual string AccessKey
{
get
{
if (this._webControlFlags[4])
{
string str = (string) this.ViewState["AccessKey"];
if (str != null)
{
return str;
}
}
return string.Empty;
}
set
{
if ((value != null) && (value.Length > 1))
{
throw new ArgumentOutOfRangeException("value", SR.GetString("WebControl_InvalidAccessKey"));
}
this.ViewState["AccessKey"] = value;
this._webControlFlags.Set(4);
}
}
[Browsable(false), WebSysDescription("WebControl_Attributes"), DesignerSerializationVisibility(0)]
public AttributeCollection Attributes
{
get
{
if (this.attrColl == null)
{
if (this.attrState == null)
{
this.attrState = new StateBag(true);
if (base.IsTrackingViewState)
{
this.attrState.TrackViewState();
}
}
this.attrColl = new AttributeCollection(this.attrState);
}
return this.attrColl;
}
}
[DefaultValue(typeof(Color), ""), TypeConverter(typeof(WebColorConverter)), WebSysDescription("WebControl_BackColor"), WebCategory("Appearance")]
public virtual Color BackColor
{
get
{
if (!this.ControlStyleCreated)
{
return Color.Empty;
}
return this.ControlStyle.BackColor;
}
set
{
this.ControlStyle.BackColor = value;
}
}
[WebCategory("Appearance"), DefaultValue(typeof(Color), ""), WebSysDescription("WebControl_BorderColor"), TypeConverter(typeof(WebColorConverter))]
public virtual Color BorderColor
{
get
{
if (!this.ControlStyleCreated)
{
return Color.Empty;
}
return this.ControlStyle.BorderColor;
}
set
{
this.ControlStyle.BorderColor = value;
}
}
[WebCategory("Appearance"), DefaultValue(0), WebSysDescription("WebControl_BorderStyle")]
public virtual BorderStyle BorderStyle
{
get
{
if (!this.ControlStyleCreated)
{
return BorderStyle.NotSet;
}
return this.ControlStyle.BorderStyle;
}
set
{
this.ControlStyle.BorderStyle = value;
}
}
[WebSysDescription("WebControl_BorderWidth"), DefaultValue(typeof(Unit), ""), WebCategory("Appearance")]
public virtual Unit BorderWidth
{
get
{
if (!this.ControlStyleCreated)
{
return Unit.Empty;
}
return this.ControlStyle.BorderWidth;
}
set
{
this.ControlStyle.BorderWidth = value;
}
}
[Browsable(false), WebSysDescription("WebControl_ControlStyle"), DesignerSerializationVisibility(0)]
public Style ControlStyle
{
get
{
if (this.controlStyle == null)
{
this.controlStyle = this.CreateControlStyle();
if (base.IsTrackingViewState)
{
this.controlStyle.TrackViewState();
}
if (this._webControlFlags[1])
{
this._webControlFlags.Clear(1);
this.controlStyle.LoadViewState(null);
}
}
return this.controlStyle;
}
}
[DesignerSerializationVisibility(0), Browsable(false), WebSysDescription("WebControl_ControlStyleCreated"), EditorBrowsable(EditorBrowsableState.Advanced)]
public bool ControlStyleCreated
{
get
{
return (this.controlStyle != null);
}
}
[WebCategory("Appearance"), CssClassProperty, DefaultValue(""), WebSysDescription("WebControl_CSSClassName")]
public virtual string CssClass
{
get
{
if (!this.ControlStyleCreated)
{
return string.Empty;
}
return this.ControlStyle.CssClass;
}
set
{
this.ControlStyle.CssClass = value;
}
}
[DefaultValue(true), WebCategory("Behavior"), Themeable(false), Bindable(true), WebSysDescription("WebControl_Enabled")]
public virtual bool Enabled
{
get
{
return !this.flags[0x80000];
}
set
{
bool flag = !this.flags[0x80000];
if (flag != value)
{
if (!value)
{
this.flags.Set(0x80000);
}
else
{
this.flags.Clear(0x80000);
}
if (base.IsTrackingViewState)
{
this._webControlFlags.Set(2);
}
}
}
}
[Browsable(true)]
public override bool EnableTheming
{
get
{
return base.EnableTheming;
}
set
{
base.EnableTheming = value;
}
}
[WebCategory("Appearance"), WebSysDescription("WebControl_Font"), DesignerSerializationVisibility(2), NotifyParentProperty(true)]
public virtual FontInfo Font
{
get
{
return this.ControlStyle.Font;
}
}
[WebSysDescription("WebControl_ForeColor"), DefaultValue(typeof(Color), ""), WebCategory("Appearance"), TypeConverter(typeof(WebColorConverter))]
public virtual Color ForeColor
{
get
{
if (!this.ControlStyleCreated)
{
return Color.Empty;
}
return this.ControlStyle.ForeColor;
}
set
{
this.ControlStyle.ForeColor = value;
}
}
[DesignerSerializationVisibility(0), Browsable(false)]
public bool HasAttributes
{
get
{
return (((this.attrColl != null) && (this.attrColl.Count > 0)) || ((this.attrState != null) && (this.attrState.Count > 0)));
}
}
[WebCategory("Layout"), DefaultValue(typeof(Unit), ""), WebSysDescription("WebControl_Height")]
public virtual Unit Height
{
get
{
if (!this.ControlStyleCreated)
{
return Unit.Empty;
}
return this.ControlStyle.Height;
}
set
{
this.ControlStyle.Height = value;
}
}
protected internal bool IsEnabled
{
get
{
for (Control control = this; control != null; control = control.Parent)
{
if (control.flags[0x80000])
{
return false;
}
}
return true;
}
}
internal virtual bool RequiresLegacyRendering
{
get
{
return false;
}
}
[Browsable(true)]
public override string SkinID
{
get
{
return base.SkinID;
}
set
{
base.SkinID = value;
}
}
[Browsable(false), DesignerSerializationVisibility(0), WebSysDescription("WebControl_Style")]
public CssStyleCollection Style
{
get
{
return this.Attributes.CssStyle;
}
}
[DefaultValue((short) 0), WebSysDescription("WebControl_TabIndex"), WebCategory("Accessibility")]
public virtual short TabIndex
{
get
{
if (this._webControlFlags[0x10])
{
object obj2 = this.ViewState["TabIndex"];
if (obj2 != null)
{
return (short) obj2;
}
}
return 0;
}
set
{
this.ViewState["TabIndex"] = value;
this._webControlFlags.Set(0x10);
}
}
[DesignerSerializationVisibility(0), Browsable(false)]
protected virtual HtmlTextWriterTag TagKey
{
get
{
return this.tagKey;
}
}
[Browsable(false), DesignerSerializationVisibility(0)]
protected virtual string TagName
{
get
{
if ((this.tagName == null) && (this.TagKey != HtmlTextWriterTag.Unknown))
{
this.tagName = Enum.Format(typeof(HtmlTextWriterTag), this.TagKey, "G").ToLower(CultureInfo.InvariantCulture);
}
return this.tagName;
}
}
[WebCategory("Behavior"), DefaultValue(""), WebSysDescription("WebControl_Tooltip"), Localizable(true)]
public virtual string ToolTip
{
get
{
if (this._webControlFlags[8])
{
string str = (string) this.ViewState["ToolTip"];
if (str != null)
{
return str;
}
}
return string.Empty;
}
set
{
this.ViewState["ToolTip"] = value;
this._webControlFlags.Set(8);
}
}
[DefaultValue(typeof(Unit), ""), WebSysDescription("WebControl_Width"), WebCategory("Layout")]
public virtual Unit Width
{
get
{
if (!this.ControlStyleCreated)
{
return Unit.Empty;
}
return this.ControlStyle.Width;
}
set
{
this.ControlStyle.Width = value;
}
}
}
Collapse Methods
[Designer("System.Web.UI.Design.WebControls.CompositeControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), AspNetHostingPermission(SecurityAction.LinkDemand, Level=200), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=200)]
public abstract class CompositeControl : WebControl, INamingContainer, ICompositeControlDesignerAccessor
{
// Methods
protected CompositeControl()
{
}
public override void DataBind()
{
this.OnDataBinding(EventArgs.Empty);
this.EnsureChildControls();
this.DataBindChildren();
}
protected virtual void RecreateChildControls()
{
base.ChildControlsCreated = false;
this.EnsureChildControls();
}
protected internal override void Render(HtmlTextWriter writer)
{
if (base.DesignMode)
{
this.EnsureChildControls();
}
base.Render(writer);
}
void ICompositeControlDesignerAccessor.RecreateChildControls()
{
this.RecreateChildControls();
}
// Properties
public override ControlCollection Controls
{
get
{
this.EnsureChildControls();
return base.Controls;
}
}
}
Collapse Methods
[ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), Bindable(true), DefaultProperty("ID"), DesignerCategory("Code"), Designer("System.Web.UI.Design.ControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, Microsoft.VisualStudio.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), Themeable(false), ToolboxItemFilter("System.Web.UI", 3), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=200), AspNetHostingPermission(SecurityAction.LinkDemand, Level=200)]
public class Control : IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
{
// Fields
internal ControlAdapter _adapter;
private string _cachedUniqueID;
private ControlState _controlState;
private string _id;
private Control _namingContainer;
private OccasionalFields _occasionalFields;
internal Page _page;
private Control _parent;
private TemplateControl _templateControl;
private VirtualPath _templateSourceVirtualDirectory;
private StateBag _viewState;
private const int automaticIDCount = 0x80;
private const string automaticIDPrefix = "ctl";
private static readonly string[] automaticIDs = new string[] {
"ctl00", "ctl01", "ctl02", "ctl03", "ctl04", "ctl05", "ctl06", "ctl07", "ctl08", "ctl09", "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 string automaticLegacyIDPrefix = "_ctl";
private const int controlAdapterResolved = 0x8000;
private const int controlsCreated = 8;
private const int controlStateApplied = 0x100000;
private const int creatingControls = 0x100;
private const int designMode = 0x10000;
private const int designModeChecked = 0x20000;
private const int disableChildControlState = 0x40000;
private const int disableTheming = 0x1000;
private const int disableViewState = 4;
private const int enableThemingSet = 0x2000;
internal const bool EnableViewStateDefault = true;
internal static readonly object EventDataBinding = new object();
private static readonly object EventDisposed = new object();
internal static readonly object EventInit = new object();
internal static readonly object EventLoad = new object();
internal static readonly object EventPreRender = new object();
internal static readonly object EventUnload = new object();
internal 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;
internal const int isWebControlDisabled = 0x80000;
internal const char LEGACY_ID_SEPARATOR = ':';
private const int marked = 2;
private const int mustRenderID = 0x800;
private const int notVisibleOnPage = 0x200;
private const int styleSheetApplied = 0x4000;
private const int themeApplied = 0x400;
private const int useGeneratedID = 0x200000;
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.Set(0x80);
}
}
protected internal virtual void AddedControl(Control control, int index)
{
if (control.OwnerControl != null)
{
throw new InvalidOperationException(SR.GetString("Substitution_NotAllowed"));
}
if (control._parent != null)
{
control._parent.Controls.Remove(control);
}
control._parent = this;
control._page = this.Page;
control.flags.Clear(0x20000);
Control namingContainer = this.flags[0x80] ? this : this._namingContainer;
if (namingContainer != null)
{
control.UpdateNamingContainer(namingContainer);
if ((control._id == null) && !control.flags[0x40])
{
control.GenerateAutomaticID();
}
else if ((control._id != null) || ((control._occasionalFields != null) && (control._occasionalFields.Controls != null)))
{
namingContainer.DirtyNameTable();
}
}
if (this._controlState >= ControlState.ChildrenInitialized)
{
control.InitRecursive(namingContainer);
if (((control._controlState >= ControlState.Initialized) && (control.RareFields != null)) && control.RareFields.RequiredControlState)
{
this.Page.RegisterRequiresControlState(control);
}
if (this._controlState >= ControlState.ViewStateLoaded)
{
object savedState = null;
if ((this._occasionalFields != null) && (this._occasionalFields.ControlsViewState != null))
{
savedState = this._occasionalFields.ControlsViewState[index];
if (this.LoadViewStateByID)
{
control.EnsureID();
savedState = this._occasionalFields.ControlsViewState[control.ID];
this._occasionalFields.ControlsViewState.Remove(control.ID);
}
else
{
savedState = this._occasionalFields.ControlsViewState[index];
this._occasionalFields.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);
}
}
private void ApplySkin(Page page)
{
if (page == null)
{
throw new ArgumentNullException("page");
}
if (!this.flags[0x400] && ThemeableAttribute.IsTypeThemeable(base.GetType()))
{
page.ApplyControlSkin(this);
this.flags.Set(0x400);
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual void ApplyStyleSheetSkin(Page page)
{
if (page != null)
{
if (this.flags[0x4000])
{
throw new InvalidOperationException(SR.GetString("StyleSheetAreadyAppliedOnControl"));
}
if (page.ApplyControlStyleSheet(this))
{
this.flags.Set(0x4000);
}
}
}
protected void BuildProfileTree(string parentId, bool calcViewState)
{
int num;
calcViewState = calcViewState && !this.flags[4];
if (calcViewState)
{
num = this.EstimateStateSize(this.SaveViewState());
}
else
{
num = 0;
}
int controlStateSize = 0;
if (((this.Page != null) && (this.Page._registeredControlsRequiringControlState != null)) && this.Page._registeredControlsRequiringControlState.Contains(this))
{
controlStateSize = this.EstimateStateSize(this.SaveControlStateInternal());
}
this.Page.Trace.AddNewControl(this.UniqueID, parentId, base.GetType().FullName, num, controlStateSize);
if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
{
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].BuildProfileTree(this.UniqueID, calcViewState);
}
}
}
private void ClearCachedUniqueIDRecursive()
{
this._cachedUniqueID = null;
if (this._occasionalFields != null)
{
this._occasionalFields.UniqueIDPrefix = null;
if (this._occasionalFields.Controls != null)
{
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].ClearCachedUniqueIDRecursive();
}
}
}
}
protected void ClearChildControlState()
{
if (this.ControlState >= ControlState.Initialized)
{
this.flags.Set(0x40000);
if (this.Page != null)
{
this.Page.RegisterRequiresClearChildControlState(this);
}
}
}
protected void ClearChildState()
{
this.ClearChildControlState();
this.ClearChildViewState();
}
protected void ClearChildViewState()
{
if (this._occasionalFields != null)
{
this._occasionalFields.ControlsViewState = null;
}
}
internal void ClearNamingContainer()
{
this.EnsureOccasionalFields();
this._occasionalFields.NamedControlsID = 0;
this.DirtyNameTable();
}
protected internal virtual void CreateChildControls()
{
}
protected virtual ControlCollection CreateControlCollection()
{
return new ControlCollection(this);
}
public virtual void DataBind()
{
this.DataBind(true);
}
protected virtual void DataBind(bool raiseOnDataBinding)
{
bool flag = false;
if (this.IsBindingContainer)
{
bool flag2;
object dataItem = DataBinder.GetDataItem(this, out flag2);
if (flag2 && (this.Page != null))
{
this.Page.PushDataBindingContext(dataItem);
flag = true;
}
}
try
{
if (raiseOnDataBinding)
{
this.OnDataBinding(EventArgs.Empty);
}
this.DataBindChildren();
}
finally
{
if (flag)
{
this.Page.PopDataBindingContext();
}
}
}
protected virtual void DataBindChildren()
{
if (this.HasControls())
{
this.EnsureOccasionalFields();
string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
try
{
try
{
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].DataBind();
}
}
finally
{
this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
}
}
catch
{
throw;
}
}
}
internal void DirtyNameTable()
{
if (this._occasionalFields != null)
{
this._occasionalFields.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);
}
}
}
if (this._occasionalFields != null)
{
this._occasionalFields.Dispose();
}
}
protected virtual void EnsureChildControls()
{
if (!this.ChildControlsCreated && !this.flags[0x100])
{
this.flags.Set(0x100);
try
{
this.ResolveAdapter();
if (this._adapter != null)
{
this._adapter.CreateChildControls();
}
else
{
this.CreateChildControls();
}
this.ChildControlsCreated = true;
}
finally
{
this.flags.Clear(0x100);
}
}
}
protected void EnsureID()
{
if (this._namingContainer != null)
{
if (this._id == null)
{
this.GenerateAutomaticID();
}
this.flags.Set(0x800);
}
}
private void EnsureNamedControlsTable()
{
this._occasionalFields.NamedControls = new HybridDictionary(this._occasionalFields.NamedControlsID, true);
this.FillNamedControlsTable(this, this._occasionalFields.Controls);
}
private void EnsureOccasionalFields()
{
if (this._occasionalFields == null)
{
this._occasionalFields = new OccasionalFields();
}
}
internal int EstimateStateSize(object state)
{
if (state == null)
{
return 0;
}
return Util.SerializeWithAssert(new ObjectStateFormatter(), state).Length;
}
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.EnsureOccasionalFields();
namingContainer._occasionalFields.NamedControls.Add(control._id, control);
}
catch
{
throw new HttpException(SR.GetString("Duplicate_id_used", new object[] { 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.HasControls() && (this._occasionalFields.NamedControls == null))
{
this.EnsureNamedControlsTable();
}
if ((this._occasionalFields == null) || (this._occasionalFields.NamedControls == null))
{
return null;
}
char[] anyOf = new char[] { '$', ':' };
int num = id.IndexOfAny(anyOf, pathOffset);
if (num == -1)
{
str = id.Substring(pathOffset);
return (this._occasionalFields.NamedControls[str] as Control);
}
str = id.Substring(pathOffset, num - pathOffset);
Control control2 = this._occasionalFields.NamedControls[str] as Control;
if (control2 == null)
{
return null;
}
return control2.FindControl(id, num + 1);
}
public virtual void Focus()
{
this.Page.SetFocus(this);
}
private void GenerateAutomaticID()
{
this.flags.Set(0x200000);
this._namingContainer.EnsureOccasionalFields();
int index = this._namingContainer._occasionalFields.NamedControlsID++;
if (this.EnableLegacyRendering)
{
this._id = "_ctl" + index.ToString(NumberFormatInfo.InvariantInfo);
}
else if (index < 0x80)
{
this._id = automaticIDs[index];
}
else
{
this._id = "ctl" + index.ToString(NumberFormatInfo.InvariantInfo);
}
this._namingContainer.DirtyNameTable();
}
[SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
protected virtual IDictionary GetDesignModeState()
{
ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
if (rareFieldsEnsured.DesignModeState == null)
{
rareFieldsEnsured.DesignModeState = new HybridDictionary();
}
return rareFieldsEnsured.DesignModeState;
}
internal virtual TemplateControl GetTemplateControl()
{
if ((this._templateControl == null) && (this.Parent != null))
{
this._templateControl = this.Parent.GetTemplateControl();
}
return this._templateControl;
}
internal virtual string GetUniqueIDPrefix()
{
this.EnsureOccasionalFields();
if (this._occasionalFields.UniqueIDPrefix == null)
{
string uniqueID = this.UniqueID;
if (!string.IsNullOrEmpty(uniqueID))
{
this._occasionalFields.UniqueIDPrefix = uniqueID + this.IdSeparator;
}
else
{
this._occasionalFields.UniqueIDPrefix = string.Empty;
}
}
return this._occasionalFields.UniqueIDPrefix;
}
internal XhtmlConformanceSection GetXhtmlConformanceSection()
{
HttpContext context = this.Context;
if (context != null)
{
return RuntimeConfig.GetConfig(context).XhtmlConformance;
}
return RuntimeConfig.GetConfig().XhtmlConformance;
}
public virtual bool HasControls()
{
return (((this._occasionalFields != null) && (this._occasionalFields.Controls != null)) && (this._occasionalFields.Controls.Count > 0));
}
protected bool HasEvents()
{
return ((this._occasionalFields != null) && (this._occasionalFields.Events != null));
}
internal bool HasRenderDelegate()
{
return ((this.RareFields != null) && (this.RareFields.RenderMethod != null));
}
internal bool HasRenderingData()
{
if (!this.HasControls())
{
return this.HasRenderDelegate();
}
return true;
}
internal virtual void InitRecursive(Control namingContainer)
{
this.ResolveAdapter();
if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
{
if (this.flags[0x80])
{
namingContainer = this;
}
string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
Control control = this._occasionalFields.Controls[i];
control.UpdateNamingContainer(namingContainer);
if (((control._id == null) && (namingContainer != null)) && !control.flags[0x40])
{
control.GenerateAutomaticID();
}
control._page = this.Page;
control.InitRecursive(namingContainer);
}
this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
}
if (this._controlState < ControlState.Initialized)
{
this._controlState = ControlState.ChildrenInitialized;
if (((this.Page != null) && !this.DesignMode) && (this.Page.ContainsTheme && this.EnableTheming))
{
this.ApplySkin(this.Page);
}
if (this._adapter != null)
{
this._adapter.OnInit(EventArgs.Empty);
}
else
{
this.OnInit(EventArgs.Empty);
}
this._controlState = ControlState.Initialized;
}
this.TrackViewState();
}
internal bool IsDescendentOf(Control ancestor)
{
Control parent = this;
while ((parent != ancestor) && (parent.Parent != null))
{
parent = parent.Parent;
}
return (parent == ancestor);
}
protected bool IsLiteralContent()
{
return ((((this._occasionalFields != null) && (this._occasionalFields.Controls != null)) && (this._occasionalFields.Controls.Count == 1)) && (this._occasionalFields.Controls[0] is LiteralControl));
}
internal void LoadChildViewStateByID(ArrayList childState)
{
int count = childState.Count;
for (int i = 0; i < count; i += 2)
{
string id = (string) childState[i];
object savedState = childState[i + 1];
Control control = this.FindControl(id);
if (control != null)
{
control.LoadViewStateRecursive(savedState);
}
else
{
this.EnsureOccasionalFields();
if (this._occasionalFields.ControlsViewState == null)
{
this._occasionalFields.ControlsViewState = new Hashtable();
}
this._occasionalFields.ControlsViewState[id] = savedState;
}
}
}
internal void LoadChildViewStateByIndex(ArrayList childState)
{
ControlCollection controls = this.Controls;
int count = controls.Count;
int num2 = childState.Count;
for (int i = 0; i < num2; i += 2)
{
int num4 = (int) childState[i];
object savedState = childState[i + 1];
if (num4 < count)
{
controls[num4].LoadViewStateRecursive(savedState);
}
else
{
this.EnsureOccasionalFields();
if (this._occasionalFields.ControlsViewState == null)
{
this._occasionalFields.ControlsViewState = new Hashtable();
}
this._occasionalFields.ControlsViewState[num4] = savedState;
}
}
}
protected internal virtual void LoadControlState(object savedState)
{
}
internal void LoadControlStateInternal(object savedStateObj)
{
if (!this.flags[0x100000])
{
this.flags.Set(0x100000);
Pair pair = (Pair) savedStateObj;
if (pair != null)
{
Page page = this.Page;
if ((page == null) || page.ShouldLoadControlState(this))
{
if (pair.First != null)
{
this.LoadControlState(pair.First);
}
if ((this._adapter != null) && (pair.Second != null))
{
this._adapter.LoadAdapterControlState(pair.Second);
}
}
}
}
}
internal virtual void LoadRecursive()
{
if (this._controlState < ControlState.Loaded)
{
if (this._adapter != null)
{
this._adapter.OnLoad(EventArgs.Empty);
}
else
{
this.OnLoad(EventArgs.Empty);
}
}
if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
{
string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].LoadRecursive();
}
this._occasionalFields.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)
{
if (!((bool) obj2))
{
this.flags.Set(0x10);
}
else
{
this.flags.Clear(0x10);
}
this.flags.Set(0x20);
}
}
}
internal void LoadViewStateRecursive(object savedState)
{
if ((savedState != null) && !this.flags[4])
{
if ((this.Page != null) && this.Page.IsPostBack)
{
object first = null;
object state = null;
ArrayList childState = null;
Pair pair = savedState as Pair;
if (pair != null)
{
first = pair.First;
childState = (ArrayList) pair.Second;
}
else
{
Triplet triplet = (Triplet) savedState;
first = triplet.First;
state = triplet.Second;
childState = (ArrayList) triplet.Third;
}
try
{
if ((state != null) && (this._adapter != null))
{
this._adapter.LoadAdapterViewState(state);
}
if (first != null)
{
this.LoadViewState(first);
}
if (childState != null)
{
if (this.LoadViewStateByID)
{
this.LoadChildViewStateByID(childState);
}
else
{
this.LoadChildViewStateByIndex(childState);
}
}
}
catch (InvalidCastException)
{
throw new HttpException(SR.GetString("Controls_Cant_Change_Between_Posts"));
}
catch (IndexOutOfRangeException)
{
throw new HttpException(SR.GetString("Controls_Cant_Change_Between_Posts"));
}
}
this._controlState = ControlState.ViewStateLoaded;
}
}
protected internal string MapPathSecure(string virtualPath)
{
string str;
VirtualPath path;
if (string.IsNullOrEmpty(virtualPath))
{
throw new ArgumentNullException("virtualPath", SR.GetString("VirtualPath_Length_Zero"));
}
this.ResolvePhysicalOrVirtualPath(virtualPath, out path, out str);
if (str == null)
{
str = path.MapPathInternal(this.TemplateControlVirtualDirectory, true);
}
HttpRuntime.CheckFilePermission(str);
return str;
}
protected virtual bool OnBubbleEvent(object source, EventArgs args)
{
return false;
}
protected virtual void OnDataBinding(EventArgs e)
{
if (this.HasEvents())
{
EventHandler handler = this._occasionalFields.Events[EventDataBinding] as EventHandler;
if (handler != null)
{
handler(this, e);
}
}
}
protected internal virtual void OnInit(EventArgs e)
{
if (this.HasEvents())
{
EventHandler handler = this._occasionalFields.Events[EventInit] as EventHandler;
if (handler != null)
{
handler(this, e);
}
}
}
protected internal virtual void OnLoad(EventArgs e)
{
if (this.HasEvents())
{
EventHandler handler = this._occasionalFields.Events[EventLoad] as EventHandler;
if (handler != null)
{
handler(this, e);
}
}
}
protected internal virtual void OnPreRender(EventArgs e)
{
if (this.HasEvents())
{
EventHandler handler = this._occasionalFields.Events[EventPreRender] as EventHandler;
if (handler != null)
{
handler(this, e);
}
}
}
protected internal virtual void OnUnload(EventArgs e)
{
if (this.HasEvents())
{
EventHandler handler = this._occasionalFields.Events[EventUnload] as EventHandler;
if (handler != null)
{
handler(this, e);
}
}
}
protected internal Stream OpenFile(string path)
{
string physicalPath = null;
VirtualFile file = null;
path = path.Trim();
if (UrlPath.IsAbsolutePhysicalPath(path))
{
physicalPath = path;
}
else
{
file = HostingEnvironment.VirtualPathProvider.GetFile(path);
MapPathBasedVirtualFile file2 = file as MapPathBasedVirtualFile;
if (file2 != null)
{
physicalPath = file2.PhysicalPath;
}
}
if (physicalPath != null)
{
HttpRuntime.CheckFilePermission(physicalPath);
}
if (file != null)
{
return file.Open();
}
return new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
internal Stream OpenFileAndGetDependency(VirtualPath virtualPath, string physicalPath, out CacheDependency dependency)
{
Stream stream;
if ((physicalPath == null) && HostingEnvironment.UsingMapPathBasedVirtualPathProvider)
{
physicalPath = virtualPath.MapPathInternal(this.TemplateControlVirtualDirectory, true);
}
if (physicalPath != null)
{
HttpRuntime.CheckFilePermission(physicalPath);
stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
dependency = new CacheDependency(0, physicalPath);
return stream;
}
stream = virtualPath.OpenFile();
dependency = VirtualPathProvider.GetCacheDependency(virtualPath);
return stream;
}
internal virtual void PreRenderRecursiveInternal()
{
if (!this.Visible)
{
this.flags.Set(0x10);
}
else
{
this.flags.Clear(0x10);
this.EnsureChildControls();
if (this._adapter != null)
{
this._adapter.OnPreRender(EventArgs.Empty);
}
else
{
this.OnPreRender(EventArgs.Empty);
}
if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
{
string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].PreRenderRecursiveInternal();
}
this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
}
}
this._controlState = ControlState.PreRendered;
}
internal void PreventAutoID()
{
if (!this.flags[0x80])
{
this.flags.Set(0x40);
}
}
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 (control.OwnerControl != null)
{
throw new InvalidOperationException(SR.GetString("Substitution_NotAllowed"));
}
if ((this._namingContainer != null) && (control._id != null))
{
this._namingContainer.DirtyNameTable();
}
control.UnloadRecursive(false);
control._parent = null;
control._page = null;
control._namingContainer = null;
if (!(control is TemplateControl))
{
control._templateSourceVirtualDirectory = null;
}
control._templateControl = null;
control.flags.Clear(0x800);
control.ClearCachedUniqueIDRecursive();
}
protected internal virtual void Render(HtmlTextWriter writer)
{
this.RenderChildren(writer);
}
protected internal virtual void RenderChildren(HtmlTextWriter writer)
{
ICollection children = (this._occasionalFields == null) ? null : ((ICollection) this._occasionalFields.Controls);
this.RenderChildrenInternal(writer, children);
}
internal void RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
{
if ((this.RareFields != null) && (this.RareFields.RenderMethod != null))
{
writer.BeginRender();
this.RareFields.RenderMethod(writer, this);
writer.EndRender();
}
else if (children != null)
{
foreach (Control control in children)
{
control.RenderControl(writer);
}
}
}
public virtual void RenderControl(HtmlTextWriter writer)
{
this.RenderControl(writer, this.Adapter);
}
protected void RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
{
if (!this.flags[0x10] && !this.flags[0x200])
{
HttpContext context = (this.Page == null) ? null : this.Page._context;
if ((context != null) && context.TraceIsEnabled)
{
int bufferedLength = context.Response.GetBufferedLength();
this.RenderControlInternal(writer, adapter);
int num2 = context.Response.GetBufferedLength();
context.Trace.AddControlSize(this.UniqueID, num2 - bufferedLength);
}
else
{
this.RenderControlInternal(writer, adapter);
}
}
}
private void RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
{
if (adapter != null)
{
adapter.BeginRender(writer);
adapter.Render(writer);
adapter.EndRender(writer);
}
else
{
this.Render(writer);
}
}
private void ResetVisible()
{
this.Visible = true;
}
protected virtual ControlAdapter ResolveAdapter()
{
if (!this.flags[0x8000])
{
if (this.DesignMode)
{
this.flags.Set(0x8000);
return null;
}
HttpContext context = this.Context;
if (context != null)
{
this._adapter = context.Request.Browser.GetAdapter(this);
}
this.flags.Set(0x8000);
}
return this._adapter;
}
public string ResolveClientUrl(string relativeUrl)
{
if ((this.DesignMode && (this.Page != null)) && (this.Page.Site != null))
{
IUrlResolutionService service = (IUrlResolutionService) this.Page.Site.GetService(typeof(IUrlResolutionService));
if (service != null)
{
return service.ResolveClientUrl(relativeUrl);
}
}
if (relativeUrl == null)
{
throw new ArgumentNullException("relativeUrl");
}
string virtualPathString = VirtualPath.GetVirtualPathString(this.TemplateControlVirtualDirectory);
if (string.IsNullOrEmpty(virtualPathString))
{
return relativeUrl;
}
string str2 = this.Context.Request.ClientBaseDir.VirtualPathString;
if (!UrlPath.IsAppRelativePath(relativeUrl))
{
if (StringUtil.EqualsIgnoreCase(str2, virtualPathString))
{
return relativeUrl;
}
if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
{
return relativeUrl;
}
}
string to = UrlPath.Combine(virtualPathString, relativeUrl);
return HttpUtility.UrlPathEncode(UrlPath.MakeRelative(UrlPath.AppendSlashToPathIfNeeded(str2), to));
}
internal void ResolvePhysicalOrVirtualPath(string path, out VirtualPath virtualPath, out string physicalPath)
{
if (UrlPath.IsAbsolutePhysicalPath(path))
{
physicalPath = path;
virtualPath = null;
}
else
{
physicalPath = null;
virtualPath = this.TemplateControlVirtualDirectory.Combine(VirtualPath.Create(path));
}
}
public string ResolveUrl(string relativeUrl)
{
if (relativeUrl == null)
{
throw new ArgumentNullException("relativeUrl");
}
if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
{
return relativeUrl;
}
string appRelativeTemplateSourceDirectory = this.AppRelativeTemplateSourceDirectory;
if (string.IsNullOrEmpty(appRelativeTemplateSourceDirectory))
{
return relativeUrl;
}
string virtualPath = UrlPath.Combine(appRelativeTemplateSourceDirectory, relativeUrl);
return this.Context.Response.ApplyAppPathModifier(virtualPath);
}
protected internal virtual object SaveControlState()
{
return null;
}
internal object SaveControlStateInternal()
{
object x = this.SaveControlState();
object y = null;
if (this._adapter != null)
{
y = this._adapter.SaveAdapterControlState();
}
if ((x == null) && (y == null))
{
return null;
}
return new Pair(x, y);
}
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])
{
object y = null;
if (this._adapter != null)
{
y = this._adapter.SaveAdapterViewState();
}
object x = this.SaveViewState();
ArrayList z = null;
if (this.HasControls())
{
ControlCollection controls = this._occasionalFields.Controls;
int count = controls.Count;
bool loadViewStateByID = this.LoadViewStateByID;
for (int i = 0; i < count; i++)
{
Control control = controls[i];
object obj4 = control.SaveViewStateRecursive();
if (obj4 != null)
{
if (z == null)
{
z = new ArrayList(count);
}
if (loadViewStateByID)
{
control.EnsureID();
z.Add(control.ID);
}
else
{
z.Add(i);
}
z.Add(obj4);
}
}
}
if (this._adapter != null)
{
if (((x != null) || (y != null)) || (z != null))
{
return new Triplet(x, y, z);
}
}
else if ((x != null) || (z != null))
{
return new Pair(x, z);
}
}
return null;
}
internal void SetControlBuilder(ControlBuilder controlBuilder)
{
this.RareFieldsEnsured.ControlBuilder = controlBuilder;
}
internal void SetDesignMode()
{
this.flags.Set(0x10000);
this.flags.Set(0x20000);
}
protected virtual void SetDesignModeState(IDictionary data)
{
}
internal void SetEnableViewStateInternal(bool value)
{
if (!value)
{
this.flags.Set(4);
}
else
{
this.flags.Clear(4);
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public void SetRenderMethodDelegate(RenderMethod renderMethod)
{
this.RareFieldsEnsured.RenderMethod = renderMethod;
this.Controls.SetCollectionReadOnly("Collection_readonly_Codeblocks");
}
internal bool ShouldSerializeEnableTheming()
{
return this.flags[0x2000];
}
private bool ShouldSerializeVisible()
{
return this.flags[0x10];
}
IDictionary IControlDesignerAccessor.GetDesignModeState()
{
return this.GetDesignModeState();
}
void IControlDesignerAccessor.SetDesignModeState(IDictionary data)
{
this.SetDesignModeState(data);
}
void IControlDesignerAccessor.SetOwnerControl(Control owner)
{
if (owner == this)
{
throw new ArgumentException(SR.GetString("Control_CannotOwnSelf"), "owner");
}
this.OwnerControl = owner;
this._parent = owner.Parent;
this._page = owner.Page;
}
void IParserAccessor.AddParsedSubObject(object obj)
{
this.AddParsedSubObject(obj);
}
protected virtual void TrackViewState()
{
if (this._viewState != null)
{
this._viewState.TrackViewState();
}
this.flags.Set(2);
}
internal virtual void UnloadRecursive(bool dispose)
{
Page page = this.Page;
if ((page != null) && page.RequiresControlState(this))
{
page.UnregisterRequiresControlState(this);
this.RareFieldsEnsured.RequiredControlState = true;
}
if (this.flags[0x200000])
{
this._id = null;
this.flags.Clear(0x200000);
}
if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
{
string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
int count = this._occasionalFields.Controls.Count;
for (int i = 0; i < count; i++)
{
this._occasionalFields.Controls[i].UnloadRecursive(dispose);
}
this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
}
if (this._adapter != null)
{
this._adapter.OnUnload(EventArgs.Empty);
}
else
{
this.OnUnload(EventArgs.Empty);
}
if (dispose)
{
this.Dispose();
}
if (this.IsReloadable)
{
this._controlState = ControlState.Constructed;
}
}
private void UpdateNamingContainer(Control namingContainer)
{
if ((this._namingContainer != null) && (this._namingContainer != namingContainer))
{
this.ClearCachedUniqueIDRecursive();
}
this._namingContainer = namingContainer;
}
internal void ValidateEvent(string uniqueID)
{
this.ValidateEvent(uniqueID, string.Empty);
}
internal void ValidateEvent(string uniqueID, string eventArgument)
{
if ((this.Page != null) && this.SupportsEventValidation)
{
this.Page.ClientScript.ValidateEvent(uniqueID, eventArgument);
}
}
// Properties
protected ControlAdapter Adapter
{
get
{
if (!this.flags[0x8000])
{
this._adapter = this.ResolveAdapter();
this.flags.Set(0x8000);
}
return this._adapter;
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(0), WebSysDescription("Control_TemplateSourceDirectory")]
public string AppRelativeTemplateSourceDirectory
{
get
{
return VirtualPath.GetAppRelativeVirtualPathStringOrEmpty(this.TemplateControlVirtualDirectory);
}
[EditorBrowsable(EditorBrowsableState.Never)]
set
{
this.TemplateControlVirtualDirectory = VirtualPath.CreateNonRelativeAllowNull(value);
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(0), Bindable(false)]
public Control BindingContainer
{
get
{
Control namingContainer = this.NamingContainer;
while (namingContainer is INonBindingContainer)
{
namingContainer = namingContainer.BindingContainer;
}
return namingContainer;
}
}
protected bool ChildControlsCreated
{
get
{
return this.flags[8];
}
set
{
if (!value && this.flags[8])
{
this.Controls.Clear();
}
if (value)
{
this.flags.Set(8);
}
else
{
this.flags.Clear(8);
}
}
}
[WebSysDescription("Control_ClientID"), DesignerSerializationVisibility(0), Browsable(false)]
public virtual string ClientID
{
get
{
this.EnsureID();
string uniqueID = this.UniqueID;
if ((uniqueID != null) && (uniqueID.IndexOf(this.IdSeparator) >= 0))
{
return uniqueID.Replace(this.IdSeparator, '_');
}
return uniqueID;
}
}
protected char ClientIDSeparator
{
get
{
return '_';
}
}
[Browsable(false), DesignerSerializationVisibility(0)]
protected internal virtual HttpContext Context
{
get
{
Page page = this.Page;
if (page != null)
{
return page.Context;
}
return HttpContext.Current;
}
}
[Browsable(false), WebSysDescription("Control_Controls"), DesignerSerializationVisibility(0)]
public virtual ControlCollection Controls
{
get
{
if ((this._occasionalFields == null) || (this._occasionalFields.Controls == null))
{
this.EnsureOccasionalFields();
this._occasionalFields.Controls = this.CreateControlCollection();
}
return this._occasionalFields.Controls;
}
}
internal ControlState ControlState
{
get
{
return this._controlState;
}
set
{
this._controlState = value;
}
}
protected internal bool DesignMode
{
get
{
if (!this.flags[0x20000])
{
Page page = this.Page;
if (page != null)
{
if (page.GetDesignModeInternal())
{
this.flags.Set(0x10000);
}
else
{
this.flags.Clear(0x10000);
}
}
else if (this.Site != null)
{
if (this.Site.DesignMode)
{
this.flags.Set(0x10000);
}
else
{
this.flags.Clear(0x10000);
}
}
else if ((this.Parent != null) && this.Parent.DesignMode)
{
this.flags.Set(0x10000);
}
this.flags.Set(0x20000);
}
return this.flags[0x10000];
}
}
internal bool EnableLegacyRendering
{
get
{
Page page = this.Page;
if (page != null)
{
return (page.XhtmlConformanceMode == XhtmlConformanceMode.Legacy);
}
return ((!this.DesignMode && (this.Adapter == null)) && (this.GetXhtmlConformanceSection().Mode == XhtmlConformanceMode.Legacy));
}
}
[DefaultValue(true), Browsable(false), WebSysDescription("Control_EnableTheming"), Themeable(false), WebCategory("Behavior")]
public virtual bool EnableTheming
{
get
{
if (!this.flags[0x2000] && (this.Parent != null))
{
return this.Parent.EnableTheming;
}
return !this.flags[0x1000];
}
set
{
if ((this._controlState >= ControlState.FrameworkInitialized) && !this.DesignMode)
{
throw new InvalidOperationException(SR.GetString("PropertySetBeforePreInitOrAddToControls", new object[] { "EnableTheming" }));
}
if (!value)
{
this.flags.Set(0x1000);
}
else
{
this.flags.Clear(0x1000);
}
this.flags.Set(0x2000);
}
}
[WebSysDescription("Control_MaintainState"), Themeable(false), DefaultValue(true), WebCategory("Behavior")]
public virtual bool EnableViewState
{
get
{
return !this.flags[4];
}
set
{
this.SetEnableViewStateInternal(value);
}
}
protected EventHandlerList Events
{
get
{
this.EnsureOccasionalFields();
if (this._occasionalFields.Events == null)
{
this._occasionalFields.Events = new EventHandlerList();
}
return this._occasionalFields.Events;
}
}
protected bool HasChildViewState
{
get
{
return (((this._occasionalFields != null) && (this._occasionalFields.ControlsViewState != null)) && (this._occasionalFields.ControlsViewState.Count > 0));
}
}
[Themeable(false), WebSysDescription("Control_ID"), MergableProperty(false), Filterable(false), ParenthesizePropertyName(true)]
public virtual string ID
{
get
{
if (!this.flags[1] && !this.flags[0x800])
{
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.Set(1);
this.flags.Clear(0x200000);
if ((this._namingContainer != null) && (str != null))
{
this._namingContainer.DirtyNameTable();
}
}
}
protected char IdSeparator
{
get
{
if (this.Page != null)
{
return this.Page.IdSeparator;
}
return this.IdSeparatorFromConfig;
}
}
internal char IdSeparatorFromConfig
{
get
{
if (!this.EnableLegacyRendering)
{
return '$';
}
return ':';
}
}
internal bool IsBindingContainer
{
get
{
return ((this is INamingContainer) && !(this is INonBindingContainer));
}
}
protected internal bool IsChildControlStateCleared
{
get
{
return this.flags[0x40000];
}
}
internal bool IsParentedToUpdatePanel
{
get
{
for (Control control = this.Parent; control != null; control = control.Parent)
{
if (control is IUpdatePanel)
{
return true;
}
}
return false;
}
}
internal virtual bool IsReloadable
{
get
{
return false;
}
}
protected bool IsTrackingViewState
{
get
{
return this.flags[2];
}
}
protected internal bool IsViewStateEnabled
{
get
{
for (Control control = this; control != null; control = control.Parent)
{
if (!control.EnableViewState)
{
return false;
}
}
return true;
}
}
protected bool LoadViewStateByID
{
get
{
return ViewStateModeByIdAttribute.IsEnabled(base.GetType());
}
}
[Browsable(false), Bindable(false), DesignerSerializationVisibility(0), WebSysDescription("Control_NamingContainer")]
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;
}
}
private Control OwnerControl
{
get
{
if (this.RareFields == null)
{
return null;
}
return this.RareFields.OwnerControl;
}
set
{
this.RareFieldsEnsured.OwnerControl = value;
}
}
[DesignerSerializationVisibility(0), WebSysDescription("Control_Page"), Browsable(false), Bindable(false)]
public virtual Page Page
{
get
{
if ((this._page == null) && (this.Parent != null))
{
this._page = this.Parent.Page;
}
return this._page;
}
set
{
if (this.OwnerControl != null)
{
throw new InvalidOperationException();
}
this._page = value;
}
}
[Browsable(false), Bindable(false), DesignerSerializationVisibility(0), WebSysDescription("Control_Parent")]
public virtual Control Parent
{
get
{
return this._parent;
}
}
internal IPostBackDataHandler PostBackDataHandler
{
get
{
IPostBackDataHandler handler = this._adapter as IPostBackDataHandler;
if (handler != null)
{
return handler;
}
return (this as IPostBackDataHandler);
}
}
internal IPostBackEventHandler PostBackEventHandler
{
get
{
IPostBackEventHandler handler = this._adapter as IPostBackEventHandler;
if (handler != null)
{
return handler;
}
return (this as IPostBackEventHandler);
}
}
private ControlRareFields RareFields
{
get
{
if (this._occasionalFields != null)
{
return this._occasionalFields.RareFields;
}
return null;
}
}
private ControlRareFields RareFieldsEnsured
{
get
{
this.EnsureOccasionalFields();
ControlRareFields rareFields = this._occasionalFields.RareFields;
if (rareFields == null)
{
rareFields = new ControlRareFields();
this._occasionalFields.RareFields = rareFields;
}
return rareFields;
}
}
[Browsable(false), WebSysDescription("Control_Site"), DesignerSerializationVisibility(0), EditorBrowsable(EditorBrowsableState.Advanced)]
public ISite Site
{
get
{
if (this.OwnerControl != null)
{
return this.OwnerControl.Site;
}
if (this.RareFields != null)
{
return this.RareFields.Site;
}
return null;
}
set
{
if (this.OwnerControl != null)
{
throw new InvalidOperationException(SR.GetString("Substitution_SiteNotAllowed"));
}
this.RareFieldsEnsured.Site = value;
this.flags.Clear(0x20000);
}
}
[Browsable(false), WebSysDescription("Control_SkinId"), DefaultValue(""), Filterable(false), WebCategory("Behavior")]
public virtual string SkinID
{
get
{
if ((this._occasionalFields != null) && (this._occasionalFields.SkinId != null))
{
return this._occasionalFields.SkinId;
}
return string.Empty;
}
set
{
if (!this.DesignMode)
{
if (this.flags[0x4000])
{
throw new InvalidOperationException(SR.GetString("PropertySetBeforeStyleSheetApplied", new object[] { "SkinId" }));
}
if (this._controlState >= ControlState.FrameworkInitialized)
{
throw new InvalidOperationException(SR.GetString("PropertySetBeforePreInitOrAddToControls", new object[] { "SkinId" }));
}
}
this.EnsureOccasionalFields();
this._occasionalFields.SkinId = value;
}
}
internal string SpacerImageUrl
{
get
{
this.EnsureOccasionalFields();
if (this._occasionalFields.SpacerImageUrl == null)
{
this._occasionalFields.SpacerImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(WebControl), "Spacer.gif");
}
return this._occasionalFields.SpacerImageUrl;
}
}
private bool SupportsEventValidation
{
get
{
return SupportsEventValidationAttribute.SupportsEventValidation(base.GetType());
}
}
[DesignerSerializationVisibility(0), Browsable(false)]
ControlBuilder IControlBuilderAccessor.ControlBuilder
{
get
{
if (this.RareFields == null)
{
return null;
}
return this.RareFields.ControlBuilder;
}
}
IDictionary IControlDesignerAccessor.UserData
{
get
{
ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
if (rareFieldsEnsured.ControlDesignerAccessorUserData == null)
{
rareFieldsEnsured.ControlDesignerAccessorUserData = new HybridDictionary();
}
return rareFieldsEnsured.ControlDesignerAccessorUserData;
}
}
DataBindingCollection IDataBindingsAccessor.DataBindings
{
get
{
ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
if (rareFieldsEnsured.DataBindings == null)
{
rareFieldsEnsured.DataBindings = new DataBindingCollection();
}
return rareFieldsEnsured.DataBindings;
}
}
bool IDataBindingsAccessor.HasDataBindings
{
get
{
return (((this.RareFields != null) && (this.RareFields.DataBindings != null)) && (this.RareFields.DataBindings.Count != 0));
}
}
ExpressionBindingCollection IExpressionsAccessor.Expressions
{
get
{
ExpressionBindingCollection expressionBindings = this.RareFieldsEnsured.ExpressionBindings;
if (expressionBindings == null)
{
expressionBindings = new ExpressionBindingCollection();
this.RareFields.ExpressionBindings = expressionBindings;
}
return expressionBindings;
}
}
bool IExpressionsAccessor.HasExpressions
{
get
{
if (this.RareFields == null)
{
return false;
}
ExpressionBindingCollection expressionBindings = this.RareFields.ExpressionBindings;
return ((expressionBindings != null) && (expressionBindings.Count > 0));
}
}
[Bindable(false), DesignerSerializationVisibility(0), Browsable(false), WebSysDescription("Control_TemplateControl")]
public TemplateControl TemplateControl
{
get
{
return this.GetTemplateControl();
}
[EditorBrowsable(EditorBrowsableState.Never)]
set
{
this._templateControl = value;
}
}
internal VirtualPath TemplateControlVirtualDirectory
{
get
{
if (this._templateSourceVirtualDirectory == null)
{
TemplateControl templateControl = this.TemplateControl;
if (templateControl == null)
{
HttpContext context = this.Context;
if (context != null)
{
this._templateSourceVirtualDirectory = context.Request.CurrentExecutionFilePathObject.Parent;
}
return this._templateSourceVirtualDirectory;
}
if (templateControl != this)
{
this._templateSourceVirtualDirectory = templateControl.TemplateControlVirtualDirectory;
}
}
return this._templateSourceVirtualDirectory;
}
set
{
this._templateSourceVirtualDirectory = value;
}
}
[DesignerSerializationVisibility(0), Browsable(false), WebSysDescription("Control_TemplateSourceDirectory")]
public virtual string TemplateSourceDirectory
{
get
{
if (this.TemplateControlVirtualDirectory == null)
{
return string.Empty;
}
return this.TemplateControlVirtualDirectory.VirtualPathStringNoTrailingSlash;
}
}
[WebSysDescription("Control_UniqueID"), Browsable(false), DesignerSerializationVisibility(0)]
public virtual string UniqueID
{
get
{
if (this._cachedUniqueID == null)
{
Control namingContainer = this.NamingContainer;
if (namingContainer == null)
{
return this._id;
}
if (this._id == null)
{
this.GenerateAutomaticID();
}
if (this.Page == namingContainer)
{
this._cachedUniqueID = this._id;
}
else
{
string uniqueIDPrefix = namingContainer.GetUniqueIDPrefix();
if (uniqueIDPrefix.Length == 0)
{
return this._id;
}
this._cachedUniqueID = uniqueIDPrefix + this._id;
}
}
return this._cachedUniqueID;
}
}
[DesignerSerializationVisibility(0), Browsable(false), WebSysDescription("Control_State")]
protected virtual StateBag ViewState
{
get
{
if (this._viewState == null)
{
this._viewState = new StateBag(this.ViewStateIgnoresCase);
if (this.IsTrackingViewState)
{
this._viewState.TrackViewState();
}
}
return this._viewState;
}
}
[Browsable(false), DesignerSerializationVisibility(0)]
protected virtual bool ViewStateIgnoresCase
{
get
{
return false;
}
}
[Bindable(true), WebCategory("Behavior"), DefaultValue(true), WebSysDescription("Control_Visible")]
public virtual bool Visible
{
get
{
if (this.flags[0x10])
{
return false;
}
if ((this._parent != null) && !this.DesignMode)
{
return this._parent.Visible;
}
return true;
}
set
{
if (this.flags[2])
{
bool flag = !this.flags[0x10];
if (flag != value)
{
this.flags.Set(0x20);
}
}
if (!value)
{
this.flags.Set(0x10);
}
else
{
this.flags.Clear(0x10);
}
}
}
// Nested Types
private sealed class ControlRareFields : IDisposable
{
// Fields
public ControlBuilder ControlBuilder;
public IDictionary ControlDesignerAccessorUserData;
public DataBindingCollection DataBindings;
public IDictionary DesignModeState;
public ExpressionBindingCollection ExpressionBindings;
public Control OwnerControl;
public RenderMethod RenderMethod;
public bool RequiredControlState;
public ISite Site;
// Methods
internal ControlRareFields()
{
}
public void Dispose()
{
this.ControlBuilder = null;
if (this.OwnerControl != null)
{
this.OwnerControl.Dispose();
}
this.ControlDesignerAccessorUserData = null;
this.DesignModeState = null;
}
}
private sealed class OccasionalFields : IDisposable
{
// Fields
public ControlCollection Controls;
public IDictionary ControlsViewState;
public EventHandlerList Events;
public IDictionary NamedControls;
public int NamedControlsID;
public Control.ControlRareFields RareFields;
public string SkinId;
public string SpacerImageUrl;
public string UniqueIDPrefix;
// Methods
internal OccasionalFields()
{
}
public void Dispose()
{
if (this.Events != null)
{
this.Events.Dispose();
this.Events = null;
}
if (this.RareFields != null)
{
this.RareFields.Dispose();
}
this.ControlsViewState = null;
}
}
}
Collapse Methods
我感觉其实自定义控件自己几乎不用写多少代码,而且能从html中解脱出来,很值得学习。
如果只是呈现的话直接从上面的几个基类集成就可以了,如果需要触发事件就要实现IPostBackEventHandler接口。
我很愚蠢的用webcontrol来实现我所谓的复合控件, 最后所有子控件的事件都无法触发,所以还是使用CompositeControl的好。
本文转自today4king博客园博客,原文链接:http://www.cnblogs.com/jinzhao/archive/2009/02/19/1394194.html,如需转载请自行联系原作者