Arbitrary code in ASPX?

Buho1

Member
Joined
Mar 23, 2006
Messages
12
Location
Maryland, USA
Programming Experience
10+
Hi. I seem to recall being able to put arbitrary code in the ASPX, something like this:

VB.NET:
<asp:Label id="lbl" runat="server" Text='<%# 2 + 2 %>' />

Which would render "4" between span tags. That's a trivial example, but I would really like to automatically display a session variable:

VB.NET:
<asp:Label id="lbl" runat="server" Text='<%# Session("Username") %>' />

Yes, yes, I can do this in Page_Load(); I just recall being able to do it this way, which would be a bit faster and (arguably) more logical/readable.

Thanks!

EDIT: I should mention that the above syntax renders nothing, though it seems it is being interpreted; VB.NET syntax errors in there throw exceptions.
 
for example:
HTML:
<p><%= Session("Username")%></p>
You can search help and see there are various <% tags that have different meaning, the %= used here has similar meaning as response.write, while %# is used for data binding.
 
BEAUTIFUL! Thank you!

The first thing I did here was try searching the forums for <%# but the search engine here apparently filters out special characters. :( I tried Google Code Search for <%# but obviously that brought up the wrong results. Thanks again John!
 
Back
Top