title: how to use OutputCache in a userControl in asp.net
body: <p>I have a aspx page that have this piece of code to load a usercontrol loaded from database</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>and the ascx have an outputcache </p>
  
  <pre><code>&lt;%@ OutputCache Duration=10 VaryByParam="none" %&gt;
  </code></pre>
  
  <p>when i browse the page 
  this error comes out</p>
  
  <blockquote>
    <p>[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) +627</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:2.0.50727.3615;
    ASP.NET Version:2.0.50727.3618</p>
  </blockquote>