The difference between &lt%= and &lt%# in ASP.NET


/ Published in: C#
Save to your folder(s)

* The


Copy this code and paste it in your HTML
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12. <p>Equals: <%= this.TestValue %></p>
  13. <p>Pound: <%# this.TestValue %></p>
  14. <p>Equals label: <asp:Label runat="server" ID="_equals" Text="<%= this.TestValue %>" /></p>
  15. <p>Pound label: <asp:Label runat="server" ID="_pound" Text="<%# this.TestValue %>" /></p>
  16. </div>
  17. </form>
  18. </body>
  19. </html>
  20.  
  21. //And the code behind is:
  22.  
  23. public partial class _Default : System.Web.UI.Page
  24. {
  25. protected void Page_Load(object sender, EventArgs e)
  26. {
  27. _testValue = "2";
  28. }
  29.  
  30. protected void Page_PreRenderComplete(object sender, EventArgs e)
  31. {
  32. // DataBind();
  33. _testValue = "3";
  34. }
  35.  
  36. public string TestValue
  37. {
  38. get { return _testValue; }
  39. }
  40.  
  41. private string _testValue = "1";
  42. }

URL: http://blogs.msdn.com/dancre/archive/2007/02/13/the-difference-between-lt-and-lt-in-asp-net.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.