如何访问布局中 Web 部件属性的值?

How to access the values of web part properties in the layout?

在 Kentico 文档中我只找到如下信息...

有什么方法可以访问布局中的属性值,如下所示?我尝试使用宏,但没有用。

我只想在自定义布局中显示属性值。除了通过代码访问之外还有什么方法吗?我正在使用门户引擎,我不知道如何访问背后的代码...

布局为 ASCX,因此您将无法按照您的示例使用宏。

  • 如果只是需要数值,可以使用GetValue方法。还有 GetStringValue,如果你的 属性 的类型是 string
    <% GetStringValue("MyPropertiesValue1", string.Empty); %>
  • 如果您需要 呈现 值,您将需要调用 Page.DataBind() 并使用数据绑定表达式。您的布局看起来像这样:
    <%# GetStringValue("MyPropertiesValue1", string.Empty) %>
    <%# GetStringValue("MyPropertiesValue2", string.Empty) %>

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.DataBind();
        }
    </script>


None 如果这真的很优雅,那么您可能需要重新考虑您的方法。