2017-10-05 13 views
0

在asp控件的文本屬性中是否有任何內聯表達式使用?我一直在使用像下面這樣的資源文件中的文本。在asp.net控件的文本屬性中使用的內聯表達式

<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

你必須使用這個語法

<asp:Button ID="btnLogin" Text='<%# CustomResourceHandler.GetResourceValue("Login_Text") %>' /> 

但爲了這個工作,你必須身後調用DataBind代碼。

protected void Page_Load(object sender, EventArgs e) 
{ 
    DataBind(); 
} 
相關問題