首页 > 解决方案 > 带有条件运算符的 asp.net <%$ ... %> 语法

问题描述

<asp:Button ID="SubscribeButton" runat="server" CssClass="PopupButton" Text='<%# Eval("Payment_Method_Tkn").ToString() != "" ? "Unsubscribe"  : "Subscribe" %>'/>

完美运行。

<asp:Button ID="SubscribeButton" runat="server" CssClass="PopupButton" Text="<%$ Resources:P2CWebStrings, UnsubscribeButtonLabel %>"/> 

也可以正常工作,正确地从资源文件中获取值

然而:

<asp:Button ID="SubscribeButton" runat="server" CssClass="PopupButton" Text='<%# Eval("Payment_Method_Tkn").ToString() != "" ? "<%$ Resources:P2CWebStrings, UnsubscribeButtonLabel %>" : "<%$ Resources:P2CWebStrings, SubscribeButtonLabel %>" %>' /> 

在屏幕上显示“<%$ Resources:P2CWebStrings, UnsubscribeButtonLabel %>”而不是资源文件值。任何想法如何解决它,请。

标签: asp.nettags

解决方案


这是正确的语法:

<asp:Button ID="SubscribeButton" runat="server" CssClass="PopupButton" Text='<%# Eval("Payment_Method_Tkn").ToString() != "" ?  GetGlobalResourceObject("P2CWebStrings", "SubscribeButtonLabel") : GetGlobalResourceObject("P2CWebStrings", "UnsubscribeButtonLabel") %>'/> 

推荐阅读