Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net: ClientScript.RegisterClientScriptBlock fires before jQuery is loaded

Interesting problem here from some inherited code I recently looked at. I'm trying to add a compression module to a project. It is loading all the JS and CSS files, combining them, minifying them, and compressing them. I've tried a number of solutions, but all of them have one fatal problem.

I have some javascript that is being loaded via Page.ClientScript.RegisterClientScriptBlock in the PreRender of the MasterPage. The compression module is loading as a Script Tag link in the MasterPage, but when I run the page... the code from the PreRender is lopped on top and is giving me a '$ is undefined' error, telling me jQuery isn't loaded yet.

Furthermore, I can't seem to get past the same problem when it comes to inline javascript on content pages.

Any ideas as to what is causing this? Enlighten me as I have no clue.

like image 229
jlrolin Avatar asked Jan 21 '11 14:01

jlrolin


1 Answers

If have done this before with RegisterStartupScript (instead of RegisterClientScriptBlock) and called the $(document).ready(function() from WITHIN that script.

like image 128
Pieter van Kampen Avatar answered Oct 05 '22 23:10

Pieter van Kampen