Skip to main content

ASPxClientHtmlEditor.ReplacePlaceholders(html, placeholders) Method

Replaces placeholders with the specified values.

Declaration

ReplacePlaceholders(
    html: string,
    placeholders: any[]
): string

Parameters

Name Type Description
html string

A string value that specifies the HTML code to process.

placeholders any[]

An array of objects that specify the placeholders and values to replace them.

Returns

Type Description
string

A string value that is the resulting HTML code with the placeholders replaced.

Remarks

Use the ReplacePlaceholders method to replace placeholder values with replacements on the client side.

Note

Each object in the placeholders parameter should contain two keys called ‘value’ and ‘replacement’.

object = {
     value: yourPlaceholderValue,
     replacement: yourPlaceholderReplacement,
}

Example

var now = new Date();

function formatDate(date) {
     var hours = date.getHours();
     var minutes = date.getMinutes();
     var ampm = hours >= 12 ? 'pm' : 'am';
     hours = hours % 12;
     hours = hours ? hours : 12; // the hour '0' should be '12'
     minutes = minutes < 10 ? '0' + minutes : minutes;
     var strTime = hours + ':' + minutes + ' ' + ampm;
     return date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear() + "  " + strTime;
}

myPlaceholders = [
     {
          value: "DateTime",
          replacement: formatDate(now),     
     },
     {
          value: "Signature",
          replacement: 'Thank you,<br/> Mary Bonn',
     }
]
<dx:ASPxHtmlEditor runat="server" ID="ASPxHtmlEditor1" Width="100%" ClientInstanceName="HtmlEditor"> 
     ...
     <Placeholders>
     <dx:HtmlEditorPlaceholderItem Value="DateTime" />
     <dx:HtmlEditorPlaceholderItem Value="Signature" />
     </Placeholders>
</dx:ASPxHtmlEditor>

<dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Replace Placeholders">
    <ClientSideEvents Click="function(s, e) {
          var html = HtmlEditor.ReplacePlaceholders(HtmlEditor.GetHtml(), myPlaceholders);
          HtmlEditor.SetHtml(html);
     }" />
</dx:ASPxButton>
See Also