Would It be a bug of ASPNET?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 said:
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"+



}
 
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?
 
David said:
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 this a bug.

The "//" here is not a signal to the ASP.Net system to treat everything after 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 deactivate 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 said:
OK, that is different from what I understood, but I still would not call this a bug.

The "//" here is not a signal to the ASP.Net system to treat everything after 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 deactivate it.
You could change it into server-side comments:
<%--= Toolbar.SetButtonVisibility(Toolbar.BtnEditName, true) --%>
that way it will not execute at all.

Hans Kesting
 
Back
Top