请问Page.LoadControl("abc.ascx"); 这个Page.LoadControl具体在做什么动作?我知道是加载控件,不过这个加载具体是怎么个过程? ascx用户控件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当你激发一个服务器控件的事件时,它动态加载,可以先在放一个 placeholder usercontrol col=(usercontrol )this.page.loadcontrol(yourcontrol.ascx) palceholder.control.add(col);这样就加载了 to:ab83328523不是说这个。而是问Page到底在做什么。为什么要LoadControl,直接Controls.Add为什么不行。 说起来就是通过制定的路径,创建控件的实例反编译下,两个相关函数:private BuildResult GetVPathBuildResultInternal(VirtualPath virtualPath, bool noBuild, bool allowCrossApp, bool allowBuildInPrecompile){ if (this._compilationStage == CompilationStage.TopLevelFiles) { throw new HttpException(SR.GetString("Too_early_for_webfile", new object[] { virtualPath })); } BuildResult vPathBuildResultFromCacheInternal = this.GetVPathBuildResultFromCacheInternal(virtualPath); if (vPathBuildResultFromCacheInternal == null) { if (noBuild) { return null; } this.ValidateVirtualPathInternal(virtualPath, allowCrossApp, false); Util.CheckVirtualFileExists(virtualPath); if (this.IsNonUpdatablePrecompiledApp && !allowBuildInPrecompile) { throw new HttpException(SR.GetString("Cant_update_precompiled_app", new object[] { virtualPath })); } bool gotLock = false; try { CompilationLock.GetLock(ref gotLock); vPathBuildResultFromCacheInternal = this.GetVPathBuildResultFromCacheInternal(virtualPath); if (vPathBuildResultFromCacheInternal != null) { return vPathBuildResultFromCacheInternal; } VirtualPathSet data = CallContext.GetData("CircRefChk") as VirtualPathSet; if (data == null) { data = new VirtualPathSet(); CallContext.SetData("CircRefChk", data); } if (data.Contains(virtualPath)) { throw new HttpException(SR.GetString("Circular_include")); } data.Add(virtualPath); try { this.EnsureTopLevelFilesCompiled(); return this.CompileWebFile(virtualPath); } finally { data.Remove(virtualPath); } } finally { if (gotLock) { CompilationLock.ReleaseLock(); } } } return vPathBuildResultFromCacheInternal;} private Control LoadControl(IWebObjectFactory objectFactory, 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);} 验证登录的数据存储过程问题!!!第一次用存储过程啊!!!! 求教 ASP.net页面访问权限 的问题 用Ajax动态写入script无法看到动态写入的内容 有没有批量对gb2312与utf-8互转的软件 怎样使网页携带的参数改变形式 我有一个存储过程p_backupdb ,实现数据库的备份,我在ASP.NET下如何 ,调用这个存储过程??在线等! 动态控件的脚本响应 ASP转到.NET技术去,适合什么方面呢? 请问水晶报表是怎么回事,怎么用? 急急急,怎么在.net中引用execl的applicaton对象 站点性能优化监测工具有哪些? 用HTML控件还是用服务器控件?
usercontrol col=(usercontrol )this.page.loadcontrol(yourcontrol.ascx)
palceholder.control.add(col);
这样就加载了
private BuildResult GetVPathBuildResultInternal(VirtualPath virtualPath, bool noBuild, bool allowCrossApp, bool allowBuildInPrecompile)
{
if (this._compilationStage == CompilationStage.TopLevelFiles)
{
throw new HttpException(SR.GetString("Too_early_for_webfile", new object[] { virtualPath }));
}
BuildResult vPathBuildResultFromCacheInternal = this.GetVPathBuildResultFromCacheInternal(virtualPath);
if (vPathBuildResultFromCacheInternal == null)
{
if (noBuild)
{
return null;
}
this.ValidateVirtualPathInternal(virtualPath, allowCrossApp, false);
Util.CheckVirtualFileExists(virtualPath);
if (this.IsNonUpdatablePrecompiledApp && !allowBuildInPrecompile)
{
throw new HttpException(SR.GetString("Cant_update_precompiled_app", new object[] { virtualPath }));
}
bool gotLock = false;
try
{
CompilationLock.GetLock(ref gotLock);
vPathBuildResultFromCacheInternal = this.GetVPathBuildResultFromCacheInternal(virtualPath);
if (vPathBuildResultFromCacheInternal != null)
{
return vPathBuildResultFromCacheInternal;
}
VirtualPathSet data = CallContext.GetData("CircRefChk") as VirtualPathSet;
if (data == null)
{
data = new VirtualPathSet();
CallContext.SetData("CircRefChk", data);
}
if (data.Contains(virtualPath))
{
throw new HttpException(SR.GetString("Circular_include"));
}
data.Add(virtualPath);
try
{
this.EnsureTopLevelFilesCompiled();
return this.CompileWebFile(virtualPath);
}
finally
{
data.Remove(virtualPath);
}
}
finally
{
if (gotLock)
{
CompilationLock.ReleaseLock();
}
}
}
return vPathBuildResultFromCacheInternal;
}
private Control LoadControl(IWebObjectFactory objectFactory, 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);
}