0

Working in Kentico 7 on an Ad-Hoc page that inherits from Portal Master. I want to insert some literal script or code right before the </body> tag in the rendered ad-hoc page.

I thought I'd have to do this by editing the portal master and adding the following:

<cms:CMSPagePlaceholder ID="plcBodyEnd" runat="server">
   <LayoutTemplate>
   </LayoutTemplate>
</cms:CMSPagePlaceholder>

and then in the layout of the Ad-Hoc page do this:

<cms:CMSContent runat="server" id="cntLeft" PagePlaceholderID="plcBodyEnd">
<script type="text/javascript"> 
ProviderConnections.Transparency.initializeWidget({ }); 
</script> 
</cms:CMSContent>

This worked fine until I went to the design tab on the Ad-Hoc page, where I got the following error:

Object reference not set to an instance of an object.

I don't want to register script blocks. I just want to put text in the Ad-Hoc page that goes there before the </body> tag, which is controlled by Portal Master.

What am I doing wrong?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Caveatrob
  • 12,667
  • 32
  • 107
  • 187

1 Answers1

1

I'm not 100% sure what you are trying to achieve. Giving an example or attaching a screenshot would be very helpful.

Here are the ways of attaching JavaScript in Kentico:

Through portal engine:

  • Use JavaScript web part - that gives you an option of choosing where the script should be located

JavaScript web part

Programmatically from code-behind:

  • Use CMS.Helpers.ScriptHelper API (wrapper around ASP.NET's ClientScriptManager)
    • ScriptHelper.RegisterStartupScript() to put the script at the end of the page
    • ScriptHelper.RegisterClientScriptBlock() to put the script before page's elements
  • The difference between the two is well explained here.

Programmatically from ASPX markup:

  • Put your <script> block to a desired location in your .aspx / .ascx files
  • Evaluate a code-behind variable containing script

    <asp:Button ID="btnOK" runat="server" Text="OK" /> <script type="text/javascript"> <%= fieldWithActualScript %> </script>

Community
  • 1
  • 1
rocky
  • 7,506
  • 3
  • 33
  • 48
  • What if I want a simple placeholder? Literal control. Something I can render before

    and put script or other things in there.

    – Caveatrob Mar 02 '16 at 15:14
  • The startup script is what you want - it renders just before form's closing tag (which renders just before body's closing tag). – rocky Mar 02 '16 at 17:36