TheChampp
TheChampp

Reputation: 1437

Get String From CodeBehind

What is the difference between <%#...%> and <%=...%> ? For example I wanted to take the username of the logged in user and I tried with "<%# Membership.GetUser().UserName %>" but this didn't work. Then I tried with <%= Membership.GetUser().UserName %> and with this works. Why with the first try ("<%# Membership.GetUser().UserName %>") didn't work but the second works fine (<%= Membership.GetUser().UserName %>) ?

With this code didn't work I can't get the field from "Membership.GetUser().UserName":

<div id="profileHeader">
    <h1><%# Membership.GetUser().UserName %></h1>
</div>

With this code work I can get the field from "Membership.GetUser().UserName":

<div id="profileHeader">
    <h1><%= Membership.GetUser().UserName %></h1>
</div>

Upvotes: 1

Views: 234

Answers (2)

alexb
alexb

Reputation: 971

Abbas is correct, here is the official wiki on the subject

Code render blocks, Data binding expression and Web Forms syntax in general.

Upvotes: 2

Abbas
Abbas

Reputation: 14432

<% %>: standard code-block

<%# %>: these servertags are for data-binding expressions.

<%= %>: those are for displaying variables.

Upvotes: 3

Related Questions