Can I use <%= ... %> to set a control property in ASP.NET?

asp.net

Solution

You could use DataBinding:

<asp:TextBox 
    ID="tbName" 
    CssClass="formField" 
    MaxLength="<%# Constants.MaxCharacterLengthOfGameName %>" 
    runat="server">
</asp:TextBox>

and in your code behind Page_Load call:

tbName.DataBind(); 

or directly databind the page:

this.DataBind();

Problem

``` <asp:TextBox ID="tbName" CssClass="formField" MaxLength="<%=Constants.MaxCharacterLengthOfGameName %>" runat="server"></asp:TextBox> ``` The code above does not work. I can set the MaxLength property of the textbox in the code behind but i rather not. Is there away I can set the MaxLength property in the front-end code as above?

Original source