I am using the following in ASP.NET webcontrols :
<%@ OutputCache Duration="86400" VaryByParam="none" %>
This means that the control will be null on reload if it is already added to the cache. The problem is that on some page I want to hide this control and it would be great if this could be done from the MasterPage codebehind file(where it is loaded).
I have tried this :
if (Request.AppRelativeCurrentExecutionFilePath.ToLower().EndsWith("/sites/MySite/default.aspx") || Request.AppRelativeCurrentExecutionFilePath.ToLower().EndsWith("MySite.net"))
{
if(topGames_Mini1 != null)
{
//Load control
topGames_Mini1.visible=true;
}
}
else
{
Page.LoadControl("topGames_Mini1").Visible = false;
}
It will however throw the following exception in the else :
The file '/Bradspel/sites/MySite/community/topGames_Mini1' does not exist.
you should better place the UserControl inside a
Placeholder
control. Then simply hide/show the Placeholder depending on your conditions.The Placeholder does not render any tags for itself, so there is NO overhead of outer HTML tags.
I Assume you must have registered your UserControl in your Master page. So, place the userControl now inside a PlaceHolder control.
and in Code behind::