我可以使用<%= ...%>在ASP.NET中设置控件属性? [英] Can I use <%= ... %> to set a control property in ASP.NET?

查看:88
本文介绍了我可以使用<%= ...%>在ASP.NET中设置控件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

上面的代码不起作用.我可以在后面的代码中设置文本框的MaxLength属性,但我不愿意.是否可以像上面那样在前端代码中设置MaxLength属性?

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?

推荐答案

您可以使用DataBinding:

You could use DataBinding:

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

以及在Page_Load调用后面的代码中:

and in your code behind Page_Load call:

tbName.DataBind(); 

或直接对页面进行数据绑定:

or directly databind the page:

this.DataBind();

这篇关于我可以使用&lt;%= ...%&gt;在ASP.NET中设置控件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆