【问题标题】:How can I read the value of a custom field from my Sitecore Webforms?如何从我的 Sitecore Webforms 中读取自定义字段的值?
【发布时间】:2013-07-10 09:39:27
【问题描述】:

我正在为营销人员使用 Sitecore WebForms。我创建了一个带有自定义属性的自定义字段。自定义字段工作正常。

我想在单击提交按钮时读取自定义属性,但我不知道如何读取自定义属性。

字段中的值是 C# 参数属性,但这是 null。如何读取自定义属性的值?

相关代码:

   //Set values in dictionary
    var values = new Dictionary<String, String>();
    foreach (AdaptedControlResult field in fields)
    {
        values.Add(field.FieldName, field.Value);
    }

【问题讨论】:

  • “我想在点击提交时读取自定义属性”是什么意思?您的意思是要在表单结果中读取属性,还是在后端读取属性?
  • 您实际上是在哪里添加自定义属性的?您是否将其添加到基于Sitecore.Form.Web.UI.Controls.... 创建的控制类中,还是将其添加到您创建的实际WebControl 中以显示在前端(例如System.Web.UI.WebControls.TextBox 等)?

标签: c# sitecore web-forms-for-marketers customproperty


【解决方案1】:

我想在保存操作中读取自定义属性的值。
字段参数为空,因为我没有重写 Result 来传递参数。

解决方案是覆盖自定义字段类中的结果。

/// <summary>
/// Override the result to get the selected value in the save action
/// </summary>
public override ControlResult Result
{
    get
    {
        return new ControlResult(this.ControlName, this.textbox.Text, MaxLeadManagerFieldName);
    }
}

第三个参数是保存动作字段属性中的参数字段。
用您的自定义字段的属性填充它,您可以在保存操作中读取参数;)

【讨论】:

    猜你喜欢
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多