Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to format a Sharepoint:FormField in a view/edit form and used FormattedString, but it doesn´t work. I do this because I would like to display a number without comma separator.

<SharePoint:FormattedString FormatText="Text in field: {0}">
<SharePoint:FormField Grid.Column="0" Grid.Row="0" ControlMode="Display"
FieldName="EmployeeNumber" IncludeDescription="True"/>
</SharePoint:FormattedString>

The FormField seems not to be rendered.

share|improve this question
add comment

1 Answer 1

It renders nothing if FormatText is null or empty. Look at the code:

protected override void Render(HtmlTextWriter output)
{
    if (!string.IsNullOrEmpty(this.FormatText))
    {
        string[] args = new string[this.Controls.Count];
        int index = 0;
        StringBuilder sb = new StringBuilder();
        HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture));
        foreach (Control control in this.Controls)
        {
            if (!(control is LiteralControl))
            {
                sb.Length = 0;
                control.RenderControl(writer);
                writer.Flush();
                args[index] = sb.ToString();
                index++;
            }
        }
        string format = null;
        switch (this.EncodeMethod)
        {
            case SPEncodeMethod.NoEncode:
                format = this.FormatText;
                break;

            case SPEncodeMethod.HtmlEncode:
                format = SPHttpUtility.HtmlEncode(this.FormatText);
                break;

            case SPEncodeMethod.HtmlEncodeAllowSimpleTextFormatting:
                format = SPHttpUtility.HtmlEncodeAllowSimpleTextFormatting(this.FormatText);
                break;

            case SPEncodeMethod.EcmaScriptStringLiteralEncode:
                format = SPHttpUtility.EcmaScriptStringLiteralEncode(this.FormatText);
                break;
        }
        output.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
        output.RenderBeginTag(HtmlTextWriterTag.Span);
        string str2 = string.Empty;
        try
        {
            str2 = string.Format(CultureInfo.InvariantCulture, format, args);
        }
        catch (FormatException)
        {
            str2 = string.Format(CultureInfo.InvariantCulture, SPUtility.EscapeForStringFormat(format), args);
        }
        output.Write(str2);
        output.RenderEndTag();
    }
}
share|improve this answer
    
hi, updated question.... –  AGuyCalledGerald Nov 6 '12 at 15:46
    
Have you tried to display just SharePoint:FormField without SharePoint:FormattedString? –  Dmitry Kozlov Nov 6 '12 at 18:13
    
yes, this works. –  AGuyCalledGerald Nov 7 '12 at 9:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.