如何在asp.net中的userControl中使用OutputCache
我有一个 aspx 页面,其中包含这段代码来加载从数据库加载的用户控件
Control userControl = new Control();
userControl = LoadControl(userControlName);
((HiddenField)userControl.FindControl("HiddenFieldCategoryID")).Value = categoryID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldNewsID")).Value = newsID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldTypeID")).Value = typeID.ToString();
PlaceHolder3.Controls.Add(userControl);
ascx 有一个输出缓存
<%@ OutputCache Duration=10 VaryByParam="none" %>
,并且当我浏览该页面时, 这个错误出来了
[NullReferenceException:对象 未设置对实例的引用 目的。] Content_SectionNews.Page_Load(对象 发送者、EventArgs e) 在 c:\Documents 中 和设置\管理员\我的 文档\Visual Studio 2005\项目\AnaweenNews.root\AnaweenNews\anaween 网站\内容\SectionNews.aspx.cs:127 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp、对象 o、对象 t、EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象 发送者、EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔值 includeStagesAfterAsyncPoint) +627
版本信息:Microsoft .NET 框架版本:2.0.50727.3615; ASP.NET版本:2.0.50727.3618
I have a aspx page that have this piece of code to load a usercontrol loaded from database
Control userControl = new Control();
userControl = LoadControl(userControlName);
((HiddenField)userControl.FindControl("HiddenFieldCategoryID")).Value = categoryID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldNewsID")).Value = newsID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldTypeID")).Value = typeID.ToString();
PlaceHolder3.Controls.Add(userControl);
and the ascx have an outputcache
<%@ OutputCache Duration=10 VaryByParam="none" %>
when i browse the page
this error comes out
[NullReferenceException: Object
reference not set to an instance of an
object.]
Content_SectionNews.Page_Load(Object
sender, EventArgs e) in c:\Documents
and Settings\Administrator\My
Documents\Visual Studio
2005\Projects\AnaweenNews.root\AnaweenNews\anaween
website\Content\SectionNews.aspx.cs:127
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr
fp, Object o, Object t, EventArgs e)
+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs
e) +99
System.Web.UI.Control.LoadRecursive()
+50 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +627Version Information: Microsoft .NET
Framework Version:2.0.50727.3615;
ASP.NET Version:2.0.50727.3618
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 LoadControl 返回的类型将是 PartialCachingControl,请按照以下步骤了解如何使用 PartialCachingControl:
The type that returned from the LoadControl it will be PartialCachingControl, please follow the steps to how use the PartialCachingControl: