Binding Expressions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jumbojs
    New Member
    • May 2009
    • 20

    Binding Expressions

    Hello,

    If I wanted to use a method and return a value to use as a property value to a control like this.

    Code:
    <asp:Label ID="test" runat="server" Visible='<%#IsVisible()%'></asp:Label>
    Will this work? And why doesn't this work

    Code:
    <asp:Label ID="test" runat="server" Visible='<%=IsVisible()%'></asp:Label>
    Can you explain what happens between # and = and the difference.

    Thanks
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    This:
    Code:
    <%=  %>
    Is shorthand for Response.Write( )...it's shorthand for this:
    Code:
    <%Response.Write("...")%>
    Therefore this won't work in your code.

    However this:
    Code:
    <%#  %>
    Is used for binding to a data source. This will work. See this article on ASP.NET data binding.

    Comment

    Working...