Can't comment JavaScript in Visual Studio
In Visual Studio 2008, a JavaScript 开发者_如何学运维function, I comment the line,. It's a usercontrol, and I get it in JavaScript. I want to comment the line, but it didn't work (
whether I add //
or /* */
, it doesn't work).
var user = document.getElementById('<%=UCSeletUser.ClientID %>');
Your problem is that your JavaScript comments are just text like anything else to the ASPX processor. Anything not inside of the script markers is treated as a string literal -- it doesn't know or care that it's a JavaScript comment. It goes through the page looking for script sections (<% %>) and doing whatever is inside them, regardless of the surrounding text. (Things work slightly differently for databinding code <%# %>, but that's not relevant to your question.)
If you don't want that script block to run, you need to either take it out, or comment it out with server-side comments:
C#: //var user = document.getElementById('<%//=UCSeletUser.ClientID %>');
VB: //var user = document.getElementById('<%'=UCSeletUser.ClientID %>');
If you have multiple script sections and you don't want to comment out each one where they may be related, you can use a script section to comment out all of it:
<%--
var user = document.getElementById('<%=UCSeletUser.ClientID %>');
var someOtherVal = document.getElementById('<%=someOtherVal.ClientID %>');
var anotherVal = document.getElementById('<%=anotherVal.ClientID %>');
--%>
Of course, you can highlight multiple lines and use the Visual Studio command ctrl-K, ctrl-C to comment the lines out. Use ctrl-K, ctrl-U to uncomment.
精彩评论