Copied to clipboard

Flag this post as spam?

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


  • Paul Sørensen 304 posts 650 karma points
    Nov 22, 2009 @ 19:56
    Paul Sørensen
    0

    Registration of client script in a UserControl

     

    I have made a new user control in which I want to add a script if it's not already registrered

            if (!script.IsStartupScriptRegistered(typeof(SlideShow), "SimpleGalleryJS"))
            {
                txt = string.Format("<script type='text/javascript' src='{0}'></script>",
                     ResolveUrl("~/scripts/simplegallery.js"));
                script.RegisterClientScriptBlock(typeof(SlideShow), "SimpleGalleryJS", txt);
            }

    It does however not get added to the page. Must it be done in a different way in Umbraco?

    Thanks

    Paul S

  • Chris Koiak 700 posts 2626 karma points
    Nov 22, 2009 @ 20:30
    Chris Koiak
    0

    You can use umbraco.library.RegisterClientScriptBlock and it should work.

    You will need to mark you <head> tag with runat="server"

  • Paul Sørensen 304 posts 650 karma points
    Nov 24, 2009 @ 08:24
    Paul Sørensen
    0

    I have tried what you suggested but without luck. The runat="server" from the head section disappears when I load the page - is it a special Umbraco thing?

    The umbraco.library does not seems to have a ICleintScriptRegistrered method so how do you check that?

    Thanks

    Paul S 

  • Paul Sørensen 304 posts 650 karma points
    Nov 30, 2009 @ 23:29
    Paul Sørensen
    0

     

    Hi Chris

    I succeeded with the use of umbraco.library and the runat.. in the case where I wanted to registrer a script file. Inline script does not show up in the rendered page.

    I downloaded the source and saw that if you don't do the runat - means you don't have a header - it just fails back to the normal RegisterClientScriptBlock, so I'm still wondering why I had to use the umbraco.library to make a least one part work.

     - so why doesn't the ordinary way work ?

    Paul S

  • Chris Koiak 700 posts 2626 karma points
    Dec 01, 2009 @ 14:21
    Chris Koiak
    0

    I don't think Umbraco will have brought in any restrictions here, it allows you to register script files without using the ScriptManager

    You should be able to use the normal RegisterClientScriptBlock without any issues. You'll need to make sure you have a ScriptManager  tag on your page though.

    Cheers,

    Chris

  • Paul Sørensen 304 posts 650 karma points
    Dec 09, 2009 @ 18:19
    Paul Sørensen
    0

    Just need to add a <form id="xx" runat="server"> and it all works

    Thanks for all your comments

    Paul S

  • 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