Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK so the basic problem here is that if you use an inline expression you can NOT use it to set a property of a server-side control outside of a binding context (using a binding expression). I have inferred that this is probably because of the timing of the evaluation of these inline expressions. You can, however, render client-side markup in this way. If you want to keep the functionality purely in your aspx file, this is the way to do it.</p> <p>Edit: Based on input from Justin Keyes, it appears it IS possible to use a binding expression to set the property. You need to manually invoke <code>Page.DataBind()</code> to trigger the textbox to evaluate the expression (see answer below).</p> <p>For instance this:</p> <pre><code>&lt;asp:Label ID="lbl" runat="server" Text="&lt;%= Now.ToShortDateString() %&gt;" /&gt; </code></pre> <p>Will produce this output:</p> <blockquote> <p>&lt;%= Now.ToShortDateString() %></p> </blockquote> <p>On the other hand this:</p> <p><code>&lt;%= "&lt;span&gt;" &amp; Now.ToShortDateString() &amp; "&lt;/span&gt;"%&gt;</code></p> <p>Will produce this output:</p> <blockquote> <p>7/27/2011</p> </blockquote> <p>The "normal" way to solve this problem is just to set the <code>Label.Text</code> properties in a <code>Page.Load</code> event handler or another appropriate event handler depending on your needs, as below. This is the way I believe most people would prefer to do it, and is most easily understandable in my opinion.</p> <p>Markup:</p> <pre><code>&lt;asp:Label ID="lbl" runat="server" /&gt; </code></pre> <p>Code:</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load lbl.Text = Now.ToShortDateString() End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload