1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / JavaScriptEmbedControl

JavaScriptEmbedControl

2 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    26 Apr 2011
    Link to this post
    Hi,

    I want to use the JavascriptEmbedControl but I need to use it programmatically rather than in the markup as I have some custom/inline js.

    At what point in the page cycle can I add it to the page? I have tried:

            protected override void OnPreRender(EventArgs e) {
     
                JavaScriptEmbedControl jsControl = new JavaScriptEmbedControl();
                jsControl.ScriptEmbedPosition = Telerik.Sitefinity.Web.UI.PublicControls.Enums.ScriptEmbedPosition.BeforeBodyEndTag;
                jsControl.Url = this.Page.ClientScript.GetWebResourceUrl(typeof(SitefinityResources.Load), "SitefinityResources.Resources.Js.jquery.easing-1.3.pack.js");
                this.Page.Controls.Add(jsControl);
     
    }

    But this produces an error because controls cant be added in the prerender stage. Am I adding it to the page correctly?

    Thanks
    higgsy
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    29 Apr 2011
    Link to this post
    Hello higgsy,

    OnPreRender is too late to add contorls to the page (as the error exception informs you). Please try adding the script on PageLoad() and inform me if you need any further assistance.

    Greetings,
    Boyan Barnev
    the Telerik team

2 posts, 0 answered