More in this section
Forums / Developing with Sitefinity / Page-Level Start Up Scripts

Page-Level Start Up Scripts

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Glenn Boothe
    Glenn Boothe avatar
    1 posts
    02 Jul 2008
    23 Dec 2009
    Link to this post

    I am using Sitefinity Community Edition and I have a need to run specific javascript based on the page a user goes to.  My master page contains a 'head' contentplaceholder but I don't see anywhere I can enter a script into it.  I tried to drag a Generic Content control into the head placeholder and was greeted with an error that says "must be placed in a form tag with runat="server" (or something along those lines).  How might I run page level start up scripts in my Sitefinity installation?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    24 Dec 2009
    Link to this post
    Hi Glenn Boothe,

    The error message should appear only in edit mode, because the page is null. Once the page is saved you should not see any problems. However you can try a different way, by creating just a user control that adds the js to your head tag.

    Sample code:

    HtmlGenericControl addJs = new HtmlGenericControl("script");
    addJs .Attributes.Add("type", "text/javascript");
    addJs .Attributes.Add("src", "HERE PATH TO YOUR JS");

    or inject the code directly

    HtmlGenericControl addJs= new HtmlGenericControl("script");
    addJs.Attributes.Add("type", "text/javascript");
    addJs.InnerHtml = "alert('Hello');";

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered