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:
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.
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.
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?
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
Tom, don't work again...
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
is working on a reply...
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.