Adding script to head or top of body tag.

2 posts, 0 answers
  1. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 09 Nov 2014 Link to this post

    Hi,

    In one of the page we are trying to add script tag on the top of the head tag or on the top of the body tag.

    That page contains wizard control and there are few steps.

    We are adding different user controls in each steps.

    We are able to put script tag in the first page load.
    But from second step we are unable to add it.

    <telerik:RadScriptBlock runat="server">
        <script type="text/javascript">
            $(document).ready(addScriptElement);
            function addScriptElement() {
                    $('body').prepend(
                    "<script id='transScript'>var dataLayer = dataLayer || [];dataLayer.push({'stepName': 'Details','stepVirtualURL': 'virtual-details'})<\/script>");
            };
        </script>
    </telerik:RadScriptBlock>

    We are using Master page.
    Is there any ways we can do this? 

    Best Regards,
    Damodar
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Nov 2014 Link to this post

    Hello Damador,

    I suppose that you have Ajax enabled on the page and this is causing the presented behavior to appear. Note that   $(document).ready does not execute after Ajax calls.

    Therefore in your case I would suggest you to implement the client logic int he client pageLoad event like this:
    <telerik:RadScriptBlock runat="server">
        <script type="text/javascript">
            function pageLoad() {
                    $('body').prepend(
                    "<script id='transScript'>var dataLayer = dataLayer || [];dataLayer.push({'stepName': 'Details','stepVirtualURL': 'virtual-details'})<\/script>");
            };
        </script>
    </telerik:RadScriptBlock>
     and see how it goes.

    Regards,
    Maria Ilieva
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top