首页 > 解决方案 > 如何从 Default.aspx 文件中的 DB 获取字符串?

问题描述

我正在尝试在弹出窗口内单击按钮时显示消息。一切正常,除了我无法从数据库中获取字符串。

<button type="button" class="btn-outline" data-container="body" data-toggle="popover" data-placement="right" data-content=<% LabelManager.Get("UnitPriceExplanation"); %>>
                    [?]
</button>

如果我在数据内容中写入随机文本,它将起作用。如果我把<% LabelManager.Get("UnitPriceExplanation");它不会显示文本。所以它不会响应点击。

LabelManager.Get("UnitPriceExplanation"); 在 Default.aspx.cs 中工作正常。

我的目标是在弹出窗口中从数据库中写入文本。如何从数据库中获取字符串。

标签: c#webforms

解决方案


在 Asp.Net 中,当<% %>操作员执行一个块时,<%= %>执行代码并打印结果。您需要使用后者并将其用引号引起来。

data-content="<%= LabelManager.Get("UnitPriceExplanation") %>"

推荐阅读