This appears to work perfectly as my banners display or not just as I would expect.
However...
In my usercontrol I have some codebehind that logs the banner view. On pages where I want the banner, all is good. But, somehow, somewhere I am getting events logged for pages where the banners never appeared.
I can't figure out if another page is causing this, perhaps the not found or search page, or maybe the name of a previous page is cached and saved???
The example code I used as reference did it that way. I discovered through trial and error that the mix of client side/server side code was at issue. I moved all of the logic into the usercontrol and it appears to be working correctly. One gotcha was, if the page property has never been set, it appears the property does not exist in the XML. So, you have to test for it's existence (not null) and then if it equals 1.
Near as I can tell, the macro runs no matter what and then client side, the script portion decides to render the control or not.
.Net Usercontrol being executed even when macro excluded
This is a hard one to explain in the subject line.
In my main content template, I test for a property:
<script runat="server">
bool showBannerAds = false;
void Page_Load(object sender, System.EventArgs ea) {
try {
if (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("showBannerAds").Value == "1")
showBannerAds = true;
}
catch (System.NullReferenceException) { }
catch (System.ArgumentException) { }
}
</script>
I then decide whether to include the macro:
<% if (showBannerAds) { %>
<umbraco:Macro Alias="getBannerAds" runat="server" bannerAdType="standard" umbraco_PageTitle="[#pageTitle]"></umbraco:Macro>
<% } %>
This appears to work perfectly as my banners display or not just as I would expect.
However...
In my usercontrol I have some codebehind that logs the banner view. On pages where I want the banner, all is good. But, somehow, somewhere I am getting events logged for pages where the banners never appeared.
I can't figure out if another page is causing this, perhaps the not found or search page, or maybe the name of a previous page is cached and saved???
Any ideas?
Hi. Why not to include the logic of hiding/showing the banner straight inside your control instead of doing it on the page?
The example code I used as reference did it that way. I discovered through trial and error that the mix of client side/server side code was at issue. I moved all of the logic into the usercontrol and it appears to be working correctly. One gotcha was, if the page property has never been set, it appears the property does not exist in the XML. So, you have to test for it's existence (not null) and then if it equals 1.
Near as I can tell, the macro runs no matter what and then client side, the script portion decides to render the control or not.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.