When using "//" to comment the server side code in a web page, I found that
aspnet would only comment the first line of the gernerated code of result
page,
and that might produces an error when the gernerated code is multi-line,
because
the rest lines wouldn't be commented at all!Looks like you are using // to comment "generated" code ? Can you show us
what you do ? IMO // is for your own code.
Patrice
"David Zhu" <DavidZhu@.discussions.microsoft.com> a crit dans le message de
news:C945CDCF-5867-4CFE-A8CC-B56A26E04BA2@.microsoft.com...
> When using "//" to comment the server side code in a web page, I found
that
> aspnet would only comment the first line of the gernerated code of result
> page,
> and that might produces an error when the gernerated code is multi-line,
> because
> the rest lines wouldn't be commented at all!
>
David Zhu wrote:
> When using "//" to comment the server side code in a web page, I
> found that aspnet would only comment the first line of the gernerated
> code of result page,
> and that might produces an error when the gernerated code is
> multi-line, because
> the rest lines wouldn't be commented at all!
Not a bug, but standard behaviour. If you want to comment out
multiple lines, then *you* should do it. Hint: select the code you want
to comment out, and hit ctrl+K, ctrl+C (to reverse, select the block
and use ctrl+K, ctrl+U).
If VS.Net would automatically comment out the whole expression, then
everyone would complain that it is not possible to comment out just
a part.
Hans Kesting
You may not understand my meaning.
The problem appear under the situation, likes below:
for example, I have a function of my user control "toolbar" to return a
javascript string, that's in code behind:
public string SetButtonVisibility(string btnName, bool visible)
{
string sResult = "";
sResult = "var btnObject;\r\n"+
"var e = document.all."+this.fID+".getElementsByTagName('SPAN');\r\n"+
}
"Hans Kesting" wrote:
> David Zhu wrote:
> Not a bug, but standard behaviour. If you want to comment out
> multiple lines, then *you* should do it. Hint: select the code you want
> to comment out, and hit ctrl+K, ctrl+C (to reverse, select the block
> and use ctrl+K, ctrl+U).
> If VS.Net would automatically comment out the whole expression, then
> everyone would complain that it is not possible to comment out just
> a part.
>
> Hans Kesting
>
>
No, you might not totally understand my meaning.
The problem may occur under such situation, like below:
for example, I have a function of a tool bar control (an user control),
that's in my
code behind file, I used it to generate several lines of javascripts:
public string SetButtonVisibility(string btnName, bool visible)
{
string sResult = "";
sResult = "var e =
document.all."+this.fID+".getElementsByTagName('SPAN');\r\n"
+ "if (e) { e.style.display = "+visible.ToString().ToLower()
+"?'inline':'none';}\r\n";
}
then, I want to use this function in page AA.aspx within a javascript segmen
t:
<script language="javascript">
<%= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) %>
</script>
That's fine, and as a result, that server side code would generate two line
s:
<script language="javascript">
var e = document.all.Toolbar.getElementsByTagName('SPAN');
if (e) { e.style.display = true?'inline':'none';}
</script>
But, the problem would occur if I want to comment that server side code
using "//":
<script language="javascript">
//<%= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) %>
</script>
Then, the result would be unexpected, like this:
<script language="javascript">
//var e = document.all.Toolbar.getElementsByTagName('SPAN');
if (e) { e.style.display = true?'inline':'none';}
</script>
So, an erorr would occur, is that a bug?
"Hans Kesting" wrote:
> David Zhu wrote:
> Not a bug, but standard behaviour. If you want to comment out
> multiple lines, then *you* should do it. Hint: select the code you want
> to comment out, and hit ctrl+K, ctrl+C (to reverse, select the block
> and use ctrl+K, ctrl+U).
> If VS.Net would automatically comment out the whole expression, then
> everyone would complain that it is not possible to comment out just
> a part.
>
> Hans Kesting
>
>
David Zhu wrote:
> No, you might not totally understand my meaning.
> The problem may occur under such situation, like below:
> for example, I have a function of a tool bar control (an user
> control), that's in my
> code behind file, I used it to generate several lines of javascripts:
> public string SetButtonVisibility(string btnName, bool visible)
> {
> string sResult = "";
> sResult = "var e =
> document.all."+this.fID+".getElementsByTagName('SPAN');\r\n"
> + "if (e) { e.style.display =
> "+visible.ToString().ToLower()
> +"?'inline':'none';}\r\n"; }
> then, I want to use this function in page AA.aspx within a javascript
> segment:
> <script language="javascript">
> <%= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) %>
> </script>
> That's fine, and as a result, that server side code would generate
> two lines:
> <script language="javascript">
> var e = document.all.Toolbar.getElementsByTagName('SPAN');
> if (e) { e.style.display = true?'inline':'none';}
> </script>
> But, the problem would occur if I want to comment that server side
> code
> using "//":
> <script language="javascript">
> //<%= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) %>
> </script>
> Then, the result would be unexpected, like this:
> <script language="javascript">
> //var e = document.all.Toolbar.getElementsByTagName('SPAN');
> if (e) { e.style.display = true?'inline':'none';}
> </script>
> So, an erorr would occur, is that a bug?
>
>
OK, that is different from what I understood, but I still would not call thi
s a bug.
The "//" here is not a signal to the ASP.Net system to treat everything afte
r that as
a comment, but just two characters to send to the browser. Then you supply
some lines of code that also get sent to the browser. ASP.Net should *not* m
ake
a guess about what you might mean.
The browser then parses the javascript block, sees that the first line is pr
eceded
by "//" and treats it as a comment. Any other lines are used.
If you don't want this code to execute, you should use some other way to dea
ctivate it.
You could change it into server-side comments:
<%--= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) --%>
that way it will not execute at all.
Hans Kesting
Thanks a lot!
"Hans Kesting" wrote:
> David Zhu wrote:
> OK, that is different from what I understood, but I still would not call t
his a bug.
> The "//" here is not a signal to the ASP.Net system to treat everything af
ter that as
> a comment, but just two characters to send to the browser. Then you supply
> some lines of code that also get sent to the browser. ASP.Net should *not*
make
> a guess about what you might mean.
> The browser then parses the javascript block, sees that the first line is
preceded
> by "//" and treats it as a comment. Any other lines are used.
> If you don't want this code to execute, you should use some other way to d
eactivate it.
> You could change it into server-side comments:
> <%--= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) --%>
> that way it will not execute at all.
> Hans Kesting
>
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment