c# - ASP.net 有很多具有相同值的文字?

标签 c# asp.net literals repeat

给定内容页面上的代码:

Are you sure you want to add another <asp:Literal runat="server" id="Name1" /> to the basket?  
You already have a <asp:Literal runat="server" id="Name2" /> in your basket.  
<asp:Literal runat="server" id="Name3" /> has not yet been added to your basket.

然后在代码隐藏中:

Name1.Text = Product.Name;
Name2.Text = Product.Name;
Name3.Text = Product.Name;

我很确定这不是解决问题的最佳方法,是否有我不知道的 ASP.net 功能或设计模式?

最佳答案

为什么不用string.Format

String.Format("Are you sure you want to add another {0} to the basket? You already have a {0} in your basket. {0} has not yet been added to your basket.", Product.Name)

关于c# - ASP.net 有很多具有相同值的文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7178364/

相关文章:

字节的 Scala 十六进制文字

Python - 数字文字表达式

c# - 在 C# 中解析 JSON

c# - 在 C# 中延迟转换 IReadOnlyList

c# - 如何创建省略所有类型的自动属性的自定义?

asp.net - 在开发人员之间共享加密的 web.config

c# - LiteralExpression - ArgumentOutOfRangeException

c# - 深入学习 C# 表达式树的最佳资源是什么?

asp.net - Sustainsys.Saml2 为 ASP.NET 动态启动身份验证

c# - 如何在 ASP.NET(Web 窗体)中添加标题后缀?