asp.net - <%=.....%> question

  • Thread starter Thread starter tony collier
  • Start date Start date
T

tony collier

i have just seen this in some code:


<option

<%

if (Request.QueryString["Category"] == values)

{
Response.Write("selected");
}

%>

<%=values%>

</option>



where values is an array of string values.


I was just wondering how come <%=values%> is allowed?

shouldn't this be <% Response.Write(values) %> ?

I thought the bits between <% %> tag was supposed to be snippets of
whole code i.e. one can't write a statement that begins with an equals
sign in c# or vb?
 
In the inline asp code, if you start the expression with '=' then it
basically does a Response.Write of the result of your expression.
It's almost like saying this chunk of HTML is equal to the following
expression...
I suppose it's mostly for backwards compatibility with older (pre-.NET) ASP.

-Rob Teixeira [MVP]

tony collier said:
i have just seen this in some code:


<option

<%

if (Request.QueryString["Category"] == values)

{
Response.Write("selected");
}

%>

<%=values%>

</option>



where values is an array of string values.


I was just wondering how come <%=values%> is allowed?

shouldn't this be <% Response.Write(values) %> ?

I thought the bits between <% %> tag was supposed to be snippets of
whole code i.e. one can't write a statement that begins with an equals
sign in c# or vb?
 
Back
Top