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>
<% %> : standard code-block
<%# %> : these servertags are for data-binding expressions.
<%= %> : those are for displaying variables.
Abbas is correct, here is the official wiki on the subject
Code render blocks , Data binding expression and Web Forms syntax in general.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.