是否有任何内联表达式用于asp控件的text属性?我一直在使用如下资源文件中的文本。
<asp:Literal runat="server" ID="LtrLogin" Text="<%$ Resources:Resource, Login_Heading %>" />
<asp:Button="btnLogin" runat="server" Text="<%$ Resources:Resource, Login_Text %>" OnClick="btnLogin_Click" OnClientClick="getHitDate()" />
出于某些原因,我需要从C#方法中获取文本。我使用下面的表达式。
<%= CustomResourceHandler.GetResourceValue("Login_Heading")%> //instead of asp:Literal element
<asp:Button="btnLogin" runat="server" Text="<%= CustomResourceHandler.GetResourceValue("Login_Text")%>" OnClick="btnLogin_Click" OnClientClick="getHitDate()" />//This doesn't work
但是我无法在asp:Button元素的text属性中使用它。 有没有办法实现这一目标。
答案 0 :(得分:0)
您必须使用此语法
<asp:Button ID="btnLogin" Text='<%# CustomResourceHandler.GetResourceValue("Login_Text") %>' />
但为了实现这一点,你必须在代码中调用DataBind。
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}