in a conventional C# code block:
"myInt = (<condition> ? <true value> : <false value>)"
but what about use inside an .aspx where I want to response.write conditionally:
<% ( Discount > 0 ? Response.Write( "$" + Html.Encode(discountDto.Discount.FlatOff.ToString("#,###."): "")%>
mny thx
It’s worth understanding what the different markup tags mean within ASP.NET template markup processing:
So to emit the value of a ternary expression (err conditional operator) you can either use:
or you can writeL
If you were using databound control (like a repeater, for example), you could use the databinding format to evaluate and emit the result:
An interesting aspect of the <%# %> markup extension is that it can be used inside of attributes of a tag, whereas the other two forms (<% and <%=) can only be used in tag content (with a few special case exceptions). The example above demonstrates this.