1

when to use # used inside <% %> ?

<%# Eval()%> what is the use of # in this ?

what are the other options available like this?

Harish Singh
  • 3,359
  • 5
  • 24
  • 39
Dhinesh
  • 45
  • 5
  • possible duplicate of [What is the difference between <% %> and <%=%>?](http://stackoverflow.com/questions/197047/what-is-the-difference-between-and) – Samiey Mehdi Dec 01 '13 at 09:23

1 Answers1

2

<%#%> is known as the binding expression. The data-binding expressions can be used in attributes of server tags to assign calculated values to properties. Also they can be used like a separate tag.

You may check MSDN for details

<%# ... %>

The data-binding expression creates binding between a server control property and a data source when the control’s DataBind method of this server control is called on the page.

The following example shows how to use the data-binding expression to bind the string from a function to the Text property of a label:

<%@ Page Language="VB" %>
<script runat="server">
    Protected Function SayHello() As String
        Return "Hello World"
    End Function

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        lblHello.DataBind()
    End Sub
</script>
<html>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="lblHello" runat="server" Text="<%# SayHello%>"></asp:Label>
    </form>
</body>
</html>

what are the other options available like this?

From the same MSDN site. You may find the option like:-

  • <% ... %> embedded code blocks
  • <%= ... %> displaying expression
  • <%@ ... %> directive expression
  • <%# ... %> data-binding expression
  • <%$ ... %> expression builder
  • <%-- ... %> server-side comments block
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331