T
Teo Lachev
Hi,
How can I cache the output of user controls that are loaded dynamically
using LoadControl?
I have an aspx page which loads dynamically user controls under different
conditions as follows:
private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack)
{
switch (ucName.ToUpper())
{
case "HOME":
ucName = "Home/Home.ascx"; break;
case "SERVICES":
ucName = "Services/Services.ascx"; break;
...
}
}
UserControl userControl = (UserControl) LoadControl(ucName);
placeHolder.Controls.Add(userControl);
}
I would like to cache the output of the controls using OutputCache directive
or programatically. Currently, if I enable output caching in the user
controls, only the fist one gets loaded (its Page_Load event executed). When
I request another control it doesn't get loaded and its Page_Load doesn't
fire. For example, when I request the page for the first time, the Home user
control gest successfully loaded, but when the page posts back and requests
"Services", the Services user control never gets shown. Instead the Home
user control output is shown.
I tried overriding the control UniqueID property and assign diffrent IDs for
the controls, as well as casting to PartialCachingControl, but it didn't
help.
How can I cache the output of user controls that are loaded dynamically
using LoadControl?
I have an aspx page which loads dynamically user controls under different
conditions as follows:
private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack)
{
switch (ucName.ToUpper())
{
case "HOME":
ucName = "Home/Home.ascx"; break;
case "SERVICES":
ucName = "Services/Services.ascx"; break;
...
}
}
UserControl userControl = (UserControl) LoadControl(ucName);
placeHolder.Controls.Add(userControl);
}
I would like to cache the output of the controls using OutputCache directive
or programatically. Currently, if I enable output caching in the user
controls, only the fist one gets loaded (its Page_Load event executed). When
I request another control it doesn't get loaded and its Page_Load doesn't
fire. For example, when I request the page for the first time, the Home user
control gest successfully loaded, but when the page posts back and requests
"Services", the Services user control never gets shown. Instead the Home
user control output is shown.
I tried overriding the control UniqueID property and assign diffrent IDs for
the controls, as well as casting to PartialCachingControl, but it didn't
help.