RegisterClientScriptInclude doesn't work for some reason
I've spent at least 2 days trying anything and googling this...but for some reason I can't get RegisterClientScriptInclude to work the way everyone else has it working?
First off, I am usting .NET 3.5 Ajax,...and I am including javascript in my partial page refreshes...using this code:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MyClientCode", script, true);
It works perfectly, my javascript code contained in the script variable is included every partial refresh.
The javascript in script is actually quite extensive though, and I would like to store it in a .js file,..so logically I make a .js file and try to include it using RegisterClientScriptInclude ...however i can't for the life of my get this to work. here's the exact code:
ScriptManager.RegisterClientScriptInclude(this, typeof(Page), "mytestscript", "/js/testscript.js");
the testscript.js file is only included in FULL page refreshes...ie. when I load the page, or do a full postback....i can't get the file to be included in partial refreshes...have no idea why..when viewing the ajax POST in firebug I don't see a difference whether I include the file or not....
both of the ScriptManager Includes are being ran from the exact same place in "Page_Load"...so they should execute every partial refresh (but only the ScriptBlock does).
anyways,..any help or ideas,..or further ways I can troubl开发者_Go百科e shoot this problem, would be appreciated.
Thanks, Andrew
Here's the key:
partial page refreshes
You have to jump through special hoops to add javascript to a page after the initial load, because loading javascript later is considered a security risk by some (it's also bad for Google indexing).
Instead, register the scripts on the initial page load and just don't execute the scripts until later. If these scripts are created dynamically, I suggest you factor out the static portion and refactor as methods you can call with information returned dynamically from your page refresh.
精彩评论