public virtual void InstantiateIn(Control control) { UserControl child = (UserControl)this._objectFactory.CreateInstance(); child.InitializeAsUserControl(control.Page); control.Controls.Add(child); }
internal override Control CreateCachedControl() { Control cachedControl; if (_objectFactory != null) { cachedControl = (Control)_objectFactory.CreateInstance(); } else { // Instantiate the control cachedControl = (Control)HttpRuntime.CreatePublicInstance(_createCachedControlType, _args); } // If it's a user control, do some extra initialization UserControl uc = cachedControl as UserControl; if (uc != null) { uc.InitializeAsUserControl(Page); } cachedControl.ID = _ctrlID; return(cachedControl); }
public virtual void InstantiateIn(Control control) { UserControl uc = (UserControl)_objectFactory.CreateInstance(); uc.InitializeAsUserControl(control.Page); control.Controls.Add(uc); }
public virtual void InstantiateIn(Control control) { UserControl uc = (UserControl)HttpRuntime.CreatePublicInstance(_ctrlType); // Make sure that the user control is not used as the binding container, // since we want its *parent* to be the binding container. uc.SetNonBindingContainer(); uc.InitializeAsUserControl(control.Page); control.Controls.Add(uc); }
/// <include file='doc\TemplateControl.uex' path='docs/doc[@for="TemplateControl.LoadControl2"]/*' /> /// <devdoc> /// <para>Obtains a <see cref='System.Web.UI.UserControl'/> object from a control type.</para> /// </devdoc> internal Control LoadControl(Type t) { // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(Control), t); // Check if the user control type has a PartialCachingAttribute attribute PartialCachingAttribute cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; if (cacheAttrib == null) { // The control is not cached. Just create it. Control c = (Control)HttpRuntime.CreatePublicInstance(t); UserControl uc = c as UserControl; if (uc != null) { uc.InitializeAsUserControl(Page); } return(c); } string cacheKey; if (cacheAttrib.Shared) { // If the caching is shared, use the type of the control as the key cacheKey = t.GetHashCode().ToString(); } else { // Make sure we have reflection permission to use GetMethod below (ASURT 106196) InternalSecurityPermissions.Reflection.Assert(); HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Get a cache key based on the top two items of the caller's stack. // It's not guaranteed unique, but for all common cases, it will be StackTrace st = new StackTrace(); for (int i = 1; i < 3; i++) { StackFrame f = st.GetFrame(i); combinedHashCode.AddObject(f.GetMethod()); combinedHashCode.AddObject(f.GetNativeOffset()); } cacheKey = combinedHashCode.CombinedHashString; } // Wrap it to allow it to be cached return(new PartialCachingControl(t, cacheAttrib, "_" + cacheKey)); }
internal override Control CreateCachedControl() { Control control; if (this._objectFactory != null) { control = (Control)this._objectFactory.CreateInstance(); } else { control = (Control)HttpRuntime.CreatePublicInstance(this._createCachedControlType, this._args); } UserControl control2 = control as UserControl; if (control2 != null) { control2.InitializeAsUserControl(this.Page); } control.ID = base._ctrlID; return(control); }
private Control LoadControl(IWebObjectFactory objectFactory, System.Web.VirtualPath virtualPath, Type t, object[] parameters) { BuildResultCompiledType type = null; BuildResultNoCompileUserControl control = null; PartialCachingAttribute cachingAttribute; if (objectFactory != null) { type = objectFactory as BuildResultCompiledType; if (type != null) { t = type.ResultType; Util.CheckAssignableType(typeof(UserControl), t); } else { control = (BuildResultNoCompileUserControl)objectFactory; } } else if (t != null) { Util.CheckAssignableType(typeof(Control), t); } if (t != null) { cachingAttribute = (PartialCachingAttribute)TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cachingAttribute = control.CachingAttribute; } if (cachingAttribute == null) { Control control2; if (objectFactory != null) { control2 = (Control)objectFactory.CreateInstance(); } else { control2 = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } UserControl control3 = control2 as UserControl; if (control3 != null) { if (virtualPath != null) { control3.TemplateControlVirtualPath = virtualPath; } control3.InitializeAsUserControl(this.Page); } return(control2); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } if (!cachingAttribute.Shared) { this.AddStackContextToHashCode(combinedHashCode); } string combinedHashString = combinedHashCode.CombinedHashString; return(new PartialCachingControl(objectFactory, t, cachingAttribute, "_" + combinedHashString, parameters)); }
public void InitializeAsUserControl_Deny_Unrestricted () { UserControl uc = new UserControl (); try { uc.InitializeAsUserControl (new Page ()); } catch (TypeInitializationException tie) { // 2.0 - error initializing HttpRuntime Console.WriteLine (tie.InnerException); } }
private Control LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, object[] parameters) { // Make sure we get an object factory or a type, but not both Debug.Assert((objectFactory == null) != (t == null)); BuildResultCompiledType compiledUCResult = null; BuildResultNoCompileUserControl noCompileUCResult = null; if (objectFactory != null) { // It can be a compiled or no-compile user control compiledUCResult = objectFactory as BuildResultCompiledType; if (compiledUCResult != null) { t = compiledUCResult.ResultType; Debug.Assert(t != null); // Make sure it's a user control (VSWhidbey 428718) Util.CheckAssignableType(typeof(UserControl), t); } else { noCompileUCResult = (BuildResultNoCompileUserControl)objectFactory; Debug.Assert(noCompileUCResult != null); } } else { // Make sure the type has the correct base class (ASURT 123677) if (t != null) { Util.CheckAssignableType(typeof(Control), t); } } PartialCachingAttribute cacheAttrib; // Check if the user control has a PartialCachingAttribute attribute if (t != null) { cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cacheAttrib = noCompileUCResult.CachingAttribute; } if (cacheAttrib == null) { // The control is not cached. Just create it. Control c; if (objectFactory != null) { c = (Control)objectFactory.CreateInstance(); } else { c = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } // If it's a user control, do some extra initialization UserControl uc = c as UserControl; if (uc != null) { Debug.Assert(virtualPath != null); if (virtualPath != null) { uc.TemplateControlVirtualPath = virtualPath; } uc.InitializeAsUserControl(Page); } return(c); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Start by adding the type or object factory of the user control to the hash. // This guarantees that two unrelated user controls don't share the same cached data. if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } // If it's not shared, add some stack frames to the hash if (!cacheAttrib.Shared) { AddStackContextToHashCode(combinedHashCode); } string cacheKey = combinedHashCode.CombinedHashString; // Wrap it to allow it to be cached return(new PartialCachingControl(objectFactory, t, cacheAttrib, "_" + cacheKey, parameters)); }