I saw this in code. It blew my mind.
<% if (false) { %>
<script type="text/javascript" src="~/Scripts/jquery-1.3.2.js"></script>
<% } %>
This seems so patently illogical that it must be intentional. I can only assume that somehow this "came up", and somebody inserted this as a work-around. There are, of course, no comments.
Why would someone do this?
That's a trick to get Visual Studio to include the javascript Intellisense for jQuery without actually emitting the script to callers.
Here is an example from Scott Gu explaining it.
Intellisense in Visual Studio works for jQuery if you add that to every .aspx, .ascx file.
But instead of including it in every file it is included only in the masterpage.
Visual Studio parses the markup files and finds a reference to jQuery and then uses the provided intellisense on it.
You'll also need to add a vsdocs.js file into the project.
You can read more about it here.
if(false) is a quick and dirty way to comment out a bunch of code
is there another line of code that looks like
<script type="text/javascript" src="~/Scripts/jquery-min.1.3.2.js"></script>
or similar? My guess is whoever wrote this wanted to have an easy way to switch in the big jQuery file for debugging purposes
To comment out code.
ASP does not respect HTML comments, so some people will use this, not knowing that ASP has its own syntax for comments.
This is just like a comment, to do not execute the script.
Related
I've created a bundle of various script files that I want to be combined/minified together. In my code behind file (yes, sorry it's in VB!) I add it to a <asp:placeholder /> on the <head> like this
Me.PlhHeader.Controls.Add(New LiteralControl(Scripts.Render("~/bundles/main").ToHtmlString()))
This will work, but it always seems to output the compressed minified version, even when debug="true" in the Web.Config.
no matter what, this is what is output: <script src="/bundles/main"></script>
What do I need to do differently to make this output the individual uncompressed files when in debug mode?
EDIT
I've also tried to manually set the option BundleTable.EnableOptimizations = false and it still outputs the single minified script tag. I'm out of ideas.
Final Edit
I was doing something very dumb with some related code, but technically everything with the bundles was fine and working correctly. Problem solved for me!
I would recommend you to install the Microsoft.AspNet.WebOptimization.WebForms. It works really well.
Microsoft.AspNet.WebOptimization.WebForms
Then you can use:
<%: System.Web.Optimization.Scripts.Render("~/bundles/main") %>
Utilizing ASPX and DotNetNuke - when viewing the generated source code all of our META calls in the XHTML document HEAD are showing up on one line.
Is there an easy way to force line breaks between each call in the generated source code?
I can use <%= System.Environment.NewLine %> in the BODY but not the HEAD.
Thanks!
This could be for a number of reasons and honestly it doesn't really matter. But you might check to see if you have the whitespace filter turned on in DNN as that will remove line breaks from the content.
Morning,
I'm getting the error above when I save my aspx file.
Easy fix I here you say! Simply add </asp:Content> to the end of the code.
That gets rid of the error.... then when I press save Visual Studio DELETES the line of code.
I'm guessing there's a problem deeper in the code (some other tag which has not been closed)... but I can't find it!
So there's two questions really!
(1) Why is Visual Studio deleting code I've typed....
(2) Anyone know of a tool I can use to find missing end tags?
Thanks in advance,
Jim
Here is a link to the code
This was the offending item:
<Style Font-Names="MS Reference Sans Serif" Font-Size="9px" />
Thanks for your help guys,
Jim
VS.NET may be having difficulties parsing your file. Try this:
Create a new .aspx page that uses the same master page. Try adding your tag and see if it closes properly. If it does, then we know that VS.NET is still working to some reasonable level.
If that is the case, you can always try adding the markup that breaks to your new page, one step at a time, until you eventually see when the failure occurs.
One idea for a solution may be to simplify your .aspx file. Break down all the stuff that's between your ... tag into separate user controls, a sort of functional decomposition if possible. If it's a VS.NET parsing issue, this may make it easier for VS.NET to understand your code.
A tool to find missing end tags?
You can use functions from http://www.dotnetperls.com/xhtml
One SEO advice we got was to move all javascript to external files, so the code could be removed from the text. For fixed scripts this is not a problem, but some scripts need to be generated as they depend on some ClientId that is generated by asp.net.
Can I use the ScriptManager (from asp.net Ajax or from Telerik) to send this script to the browser or do I need to write my own component for that?
I found only ways to combine fixed files and/or embedded resources (also fixed).
How about registering the ClientIDs in an inline Javascript array/hash, and have your external JS file iterate through that?
Spiderbots do not read JavaScript blocks. This advice is plain wrong.
Some javascript can break W3C validators (and possibly cause issues with some spiderbots)
You can reduce this by placing this code around your javascript:
< !-- no script
... your javascript code and functions ...
// -->
Note: remove the space between "<" and "!" as it seems to comment out the example here :-)
I have a page that has a simple javascript in the header portion of the page:
<script type="text/javascript">
function doLogout() {
var conf = confirm("Really log out?");
if (conf === true) { //changed == to === for boolean comparison
$.post("logout.aspx");
}
}
</script>
It uses jQuery to do an AJAX post to my logout page. The only issue right now is that when I click on the link (logout) to fire this function, nothing happens. I checked FireBug's console, and it told me that the function is not defined. This has happened to me before, but I think I botched a bunch of code to fix it sometimes.
Does anyone know the proper way to fix this issue?
Edit
After doing a lot of googling and trying different things, I found this very concise and informative post. Apparently, as the linked article states, the way the script is referenced in the web site is important as it won't run properly otherwise! Hopefully this information will be useful for more people.
This can also occur if there is a syntax error earlier in your javascript code. Often this will just be interpreted as the function not existing (nor any function AFTER the error). Check the code above this code (if there is any) and this code for syntax errors.
A way to tell if the cache error is it is to open Firebug and view the Script source. If the page was cached, you won't see your code. If it loaded but has syntax errors, the code will show, though it won't "find" it.
Things to test:
1) Can you call this function from something else? Like add a <script> at the bottom of the page to call it?
2) Does the page validate? Sometimes I get screwy javascript errors if there is some busted HTML like a missing </b>
3) I've been starting to wrap my javascript in <![CDATA[ ]]> just incase I've got goofy chars in my javascript.
4) I assume you've tested this in other browsers and have the same behavior, right?
5) If you haven't installed it already, install the Web Developer firefox addon. It has a nifty toolbar menu that will disable the cache for you so everything reloads.
6) As weird as it sounds, I once hit a javascript issue that was because of how my text editor was saving UTF-8 files. I forget the details, but it was adding some byte-order-mark or something that upset the browser.
I've had this occur when the page had been cached and so it didn't load the new script in. So to fix it clear all private data from Firefox. Not sure if that helps but it sure happened to me a bunch.
Other ideas for you to test:
is the function defined in the DOM tab in FireBug?
if you call doLogout() from the FireBug console, what happens?
I assume this is not the only script on that page. Make sure that some later script is not modifying doLogout to something else
I had the same issue and tried all that's been suggested here without success.
The only way I fixed it was by discovering that in the <script src="jquery.js"> tag I was using in the head of the page I forgot to close it with its </script> causing the page to ignore all Javascript functions. So please check that your includes look like:
<script src="jquery.js"></script>
I hope that helps. Ross.
If you are using DevExpress controls these links may help you: How to register and execute a JavaScript downloaded to the client via a callback and How to register and execute a JavaScript downloaded to the client via a callback (standalone JS file) and Executing javascripts from user controls dynamically created through ASPxCallback panels
The issue might occur if you have NoScript. You should check and make sure it's not blocking said script.
I had this issue and discovered the problem was just a wrong case letter inside the name.
Call: filterCheckbox()
vs
function filterCheckBox() {}
problem: lowercase "box" vs uppercase "Box".
So check if the name is exactly the same.