Convert line breaks to break tags in Profile widgets read-mo

Posted by Community Admin on 04-Aug-2018 19:11

Convert line breaks to break tags in Profile widgets read-mode template.

All Replies

Posted by Community Admin on 25-Feb-2013 00:00

We need to be able to convert line breaks to html break tags when you display the data entered in the Users profile page under "about". I've tried going into the template and adding

<sf:TextField ID="about" runat="server" DataFieldName="About" Value='<%# (Eval("About")).ToString().Replace(System.Environment.NewLine, "<br />").Replace("\r\n" , "<br />").Replace("\r", "<br />").Replace("\n", "<br />") %>' DisplayMode="Read" Title="<%$ Resources:Labels, About %>" CssClass="sfprofileField sfprofileAbout" />

Still no break tags displayed. Viewing source code of the profile page shows the text formatted correctly so the line break characters are being saved as part of the text in the database. I don't know of any reason why the above wouldn't work but it's not.

Does anybody have any idea what kind of line break characters the sitefinity textField is using? And how to convert them to html <br /> tags?

Posted by Community Admin on 28-Feb-2013 00:00

Hello,

For this you will have to customize Sitefinity TextField control to inject the logic for changiing the line breaks with <br/>. TextField outputs asp:TextBox control accessible trough TextBoxControl object, Set properties in ConstructControl method of a class inheriting from TextField.

protected override void ConstructControl()
        
            this.TitleLabel.Text = this.Title;
            this.DescriptionLabel.Text = this.Description;
            switch (this.DisplayMode)
            
                case FieldDisplayMode.Read:
                    if (this.value != null)
                        this.LabelControl.Text = this.Value as string;
                    this.LabelControl.TabIndex = this.TabIndex;
                    break;
                case FieldDisplayMode.Write:
                    this.ExampleLabel.Text = this.Example;
                    this.TitleLabel.AssociatedControlID = this.TextBoxControl.ID;
                    if (this.value != null)
                        //the TextBoxControl is the asp:TextBox rendered on the frontend apply logic agains this control
                        this.TextBoxControl.Text = this.Value as string;
                    this.TextBoxControl.Rows = this.Rows;
 
                    if (this.IsPasswordMode)
                        this.TextBoxControl.TextMode = TextBoxMode.Password;
                    else if (this.Rows > 1)
                        this.TextBoxControl.TextMode = TextBoxMode.MultiLine;
 
                    this.ConfigureExpandableControl(this.ExpandableControlDefinition);
 
                    this.TextBoxControl.TabIndex = this.TabIndex;
                    if (!this.Expanded.GetValueOrDefault())
                    
                        this.ExpandControl.TabIndex = this.TabIndex;
                    
                    this.TabIndex = 0;
                    break;
            
        

Use the class to register new control replcement for the TextField used for the About text.

Attached is a sample class implementing this.

Regards,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-Mar-2013 00:00

Hello Stanislav,

Thank you for your reply. I'm new to sitefinity so please forgive me if the answers to my questions should be obvious.

question 1: Why would my code at the top of this thread not work? If you view the source of the profile page you can see that the carriage returns entered in the TextField while in Write mode were persisted to the database. Because the source is correctly formatted. So what Kind of line breaks are you using that couldn't be replaced by the code I have above?

question 2: If I use your CustomTextField to resolve this issue. Where do I register it? I've looked through the advanced settings and I cannot find where it should be registered in sitefinity.

Thanks for your help.

 

 

Posted by Community Admin on 06-Mar-2013 00:00

Hello,

Excuse me I have missed the registration part of my previous reply.
1.Create a class in visual studio and place the code attached in my previous reply.
2.with the class created in the project edit the control template for prolfile and register the class with the line

<%@ Register TagPrefix="custom" Namespace="SitefinityWebApp" Assembly="SitefinityWebApp" %>
add the custom textfield with
<custom:CustomTextField ID="about" runat="server" DataFieldName="About" Rows="12" DisplayMode="Write" Title="<%$ Resources:Labels, About %>" CssClass="sfprofileField sfprofileAbout" WrapperTag="li" />


<%@ Control Language="C#" %>
  <%@ Register TagPrefix="custom" Namespace="SitefinityWebApp" Assembly="SitefinityWebApp" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
 
<sf:SitefinityLabel runat="server" id="successMessageLabel" Visible="false" WrapperTagName="div" HideIfNoText="false" CssClass="sfprofileSuccessMsg" />
 
<fieldset id="formWrapper" runat="server" class="sfprofileEditFormWrp">
    <sf:SitefinityLabel runat="server" id="errorLabel" Visible="false" WrapperTagName="div" HideIfNoText="false" CssClass="sfprofileFailureMsg" />
    <asp:PlaceHolder ID="itemContainer" runat="server">
        <ol class="sfprofileFieldsList">
            <sf:TextField ID="firstName" runat="server" DataFieldName="FirstName" DisplayMode="Write" Title="<%$ Resources:Labels, FirstName %>" CssClass="sfprofileField sfprofileFirstName" WrapperTag="li" />
            <sf:TextField ID="lastName" runat="server" DataFieldName="LastName" DisplayMode="Write" Title="<%$ Resources:Labels, LastName %>" CssClass="sfprofileField sfprofileLastName" WrapperTag="li" />           
            
            <sf:ImageField ID="predefinedImageField" runat="server" SizeInPx="100" DataFieldType="Telerik.Sitefinity.Model.ContentLinks.ContentLink" WrapperTag="li"
                DisplayMode="Write" ShowDeleteImageButton="false" DefaultSrc="~/SFRes/images/Telerik.Sitefinity.Resources/Images.DefaultPhoto.png" DataFieldName="Avatar" UploadMode="InputField" CssClass="sfprofileField sfprofileAvatar" />
           <custom:CustomTextField ID="about" runat="server" DataFieldName="About" Rows="12" DisplayMode="Write" Title="<%$ Resources:Labels, About %>" CssClass="sfprofileField sfprofileAbout" WrapperTag="li" />      
      </ol>
    </asp:PlaceHolder>
    <div class="sfprofileLnkWrp">
        <asp:Button runat="server" ID="saveChanges" Text="<%$ Resources:UserProfilesResources, SaveChanges %>" CssClass="sfprofileSaveLnk" />
        <asp:HyperLink runat="server" ID="cancel" Text="<%$ Resources:UserProfilesResources, Cancel %>" CssClass="sfprofileCancelLnk" />
    </div>
</fieldset>



Regards,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 02-Sep-2015 00:00

Gregg's solution in the template works fine for me. To me, this is a much better solution since it is tied directly to a specific widget template. 

This thread is closed