2

I'm attempting to register some javascript on a Tridion-Generated page via a user control. I've created a page object that uses a generic aspx page template. The TBB for the page template contains only the registration for the usercontrol and <!-- TemplateBeginRepeat name="Components" --> @@RenderComponentPresentation()@@ <!-- TemplateEndRepeat -->. The Component Presentation contains 1 component that calls a cp that has an associated tbb that calls the usercontrol. In the usercontrol is the following code:

 protected void Page_Load(object sender, EventArgs e)
    {
         if (Request.QueryString["ID"] == "56")
        {
            ltrClassName.Text = "active";
            ClientScriptManager cs = Page.ClientScript;
            StringBuilder jscript = new StringBuilder();

            jscript.Append("<script type=text/javascript> alert('Hello World!') </");
            jscript.Append("script>");

            cs.RegisterStartupScript(this.GetType(), "PopupScript", jscript.ToString());

        }
        else
        {
            ltrClassName.Text = string.Empty;
        }
    }

When I view the published page and add ID=56 as a parameter to the url, I get 'active' and nothing else. The jscript is not part of the source.

Any reasons why this will not work with Tridion?

4
  • This should work fine. Is your component template dynamic? Make sure it is set to "Published Embedded on a page" (static). Feb 13, 2015 at 3:15
  • "The Component Presentation contains 1 component that calls a cp that has an associated tbb that calls the usercontrol." could you elaborate? How does a component call a CP which calls a usercontrol? Which code is being executed at which point (render/request)? Feb 13, 2015 at 8:21
  • The component template has a related tbb that contains a usercontrol tag. When the page is called with the 56 id, 'the ltrClassName.Text = "active";' runs as it should.
    – Freq
    Feb 13, 2015 at 19:57
  • If dynamic it could still work if the is DCP on the file system as an ascx file, right? Otherwise make sure the CT is checked in and the changes are published. Feb 14, 2015 at 20:00

1 Answer 1

2
+25

I would venture to guess this is not in any way related to Tridion but is in fact a fairly generic .Net related question.

Perhaps this explanation will help? Or in code:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "PopupScript", "javascript:alert('Hello World!');", true);
3
  • Tried the above with the same results.
    – Freq
    Feb 13, 2015 at 20:00
  • Tried the above with the same results. FYI-when I create a test page using the same setup(page that calls a usercontrol--same code in the usercontrol) it works as it should using cs.RegisterStartupScript.
    – Freq
    Feb 13, 2015 at 20:06
  • So the published page from Tridion (which should be an .aspx file) and your test page are identical (bit for bit) and it works only on your test page? Feb 16, 2015 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.