Copied to clipboard

Flag this post as spam?

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


  • Giuseppe 34 posts 56 karma points
    Nov 10, 2011 @ 12:03
    Giuseppe
    0

    RegisterStartupScript doesn't work

    Hi All,

    I've created an usercontrol in front-end site that need to register by code a javascript. So I use the method RegisterStartupScript to do this, in this way:

    this.Page.ClientScript.RegisterStartupScript(typeof(Page), "nameScript", jsScript, true);

    where jsScript is the variable that contain the script to register.

    This approach work on separate test file but doesn't work in Umbraco! My code is not register and so not execute, debug is done and by code is all correct.

    Any idea about this issue?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 10, 2011 @ 14:13
    Tom Fulton
    0

    You might try one of the umbraco.library methods instead:  umbraco.library.RegisterClientScriptBlock or umbraco.library.RegisterJavaScriptFile

    Also IIRC you need to have <head runat="server"> on your page

    -Tom

  • Giuseppe 34 posts 56 karma points
    Nov 10, 2011 @ 14:26
    Giuseppe
    0

    Tom, don't work again...

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 10, 2011 @ 18:11
    Tom Fulton
    0

    Ok, did some testing and it seems like:

    For umbraco.library.RegisterJavaScriptFile, you need to have <head runat="server"> in your template.

    For umbraco.library.RegisterClientScriptBlock or this.Page.ClientScript.RegisterStartupScript, you need to have the macro/UC wrapped in a <form runat="server"> in your template for it to work.

    Hope this helps,
    Tom

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies