1

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>

2 Answers 2

3

<% %>: standard code-block

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

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.