Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rick 36 posts 150 karma points
    Aug 29, 2013 @ 18:29
    Rick
    0

    Issue with InitializePage in header/footer

    Hey all,

    Using Umbraco 6.1.3 and am having an odd issue with InitializePage as a function within a Razor script, but ONLY if the call is within the Header or Footer.  Lemme explain...

    MasterPage Template Core:

            <body>
               
                <header class="navbar navbar-fixed-top" id="top">
                    <umbraco:Macro Alias="SiteHeader" runat="server" />
                </header>
               
                <asp:ContentPlaceHolder Id="MainContent" runat="server"></asp:ContentPlaceHolder>
               
                <footer>
                    <umbraco:Macro Alias="SiteFooter" runat="server" />
                </footer>
               
                <!-- Javascript -->
                <script type="text/javascript" src="/js/supersecret.min.js"></script>
               
            </body>

    Stripped Down InitializePage Function:

    @functions {
       
        bool test = false;
       
        protected override void InitializePage() {
            test = true;
        }

    }

    If I put that stripped down code in either the SiteHeader or the SiteFooter script those sections don't render at all with the on-screen error of "Erorr Loading MacroEngine script (file: <whichever script>)". Putting in an empty InitializePage function has the same result (eg - just the existance of the function call is making it pissy).

    All of the pages on the site are subs for the Master and render macros from within the MainContent placeholder and a few of these pages have an InitializePage function and render without issue. I've tried the stripped down one in just about every other page and am not having problems...only if I put it in the SiteHeader or SiteFooter scrips.

    All of the templates (all subs of the Master) look like this (obviously calling different macros):

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Masterpage.master" AutoEventWireup="true" %>

    <asp:content ContentPlaceHolderId="MainContent" runat="server">
        <umbraco:Macro Alias="Homepage" runat="server" />
    </asp:content>

    At first I thought is may puking about multiple InitializePage calls, but the issue still comes up if the page rendered within MainContent does not have that function call.

    I've tried commenting out the JS file(s) thinking that there may be some conflict there, but that does not appear to be the issue either. I've also tried moving the Footer macro call out of the Master and into a sub tempate that leverages the MainContent placeholder with no change. I've also tried changing the Header/Footer tags to sections/divs without any change in the behavior.

    I've done this same thing (InitializePage) in other sites running under 4.7.x with no issue.

    I've been in this rabbit hole for a few hours now and am totally at a loss.

    Any ideas?

    Thanks in advance,

    Rick

    PS - Wanting to add this to the Header so I can display a Log Out button if they are logged in...again, something that I've done under other 4.7.x sites, but never under a 6.x site.

     

  • Rick 36 posts 150 karma points
    Aug 29, 2013 @ 19:46
    Rick
    100

    Appears to be resolved...

    Apparently, if you have ANY @Html.Raw calls in your helpers, you cannot use InitializePage.  If you need the Html.Raw calls in your helpers, using RenderPage to another cshtml script with the function also resolves this issue.

    If anyone has any insight as to why this happens, I would be interested in hearing it.

    Thanks,

    Rick

Please Sign in or register to post replies

Write your reply to:

Draft