Consider the following situation:
There is a master page with a contentPlaceHolder for all javascript…
for speed issuses this section is at the bottom of the page.
my user control generates some javascript that make use of some references in the master page javascript (Jquery library)
so, if my user control is rendered before the master page javascript, it won’t work.
and this is my question:
how do I make some javascript code block inside my .ascx file to be rendered to the asp:Content JavaScript in the .aspx page
or maybe my all thinking is worng?
Thanks!
See if this works for you:
Where in the “bottom” of the Master Page? If you move it inside the closing server-side form control and use
ClientScript.RegisterStartupScriptin your user control, it will inject that script of your control “before the closing<form/>tag” (which will be after your your static script call).Master Page – right above the closing server-side ASP.Net
</form>:Content Page (nothing special):
User Control:
This is how its rendered (HTML view source in browser):
As advertised,
alert('foo');is below the “pre-defined” jq cdn call….