General Information
.NET Subscription
Desktop
Web
Controls and Extensions
Mainteinance Mode
Enterprise and Analytic Tools
Quality Assurance and Productivity
Frameworks and Libraries
General Information
.NET Subscription
Desktop
Web
Controls and Extensions
Mainteinance Mode
Enterprise and Analytic Tools
Quality Assurance and Productivity
Frameworks and Libraries
ASPxHtmlEditor.ReplacePlaceholders(String, Object) Method
Replaces placeholders with the specified values.
Namespace: DevExpress.Web.ASPxHtmlEditor
Assembly: DevExpress.Web.ASPxHtmlEditor.v19.2.dll
Declaration
public static string ReplacePlaceholders(
string html,
object placeholders
)
Public Shared Function ReplacePlaceholders(
html As String,
placeholders As Object
) As String
Parameters
Name | Type | Description |
---|---|---|
html | String | A string value that specifies the HTML code to process. |
placeholders | Object | An object that specifies the placeholders and values to replace them. |
Returns
Type | Description |
---|---|
String | A string value that is the resulting HTML code with the placeholders replaced. |
Examples
This example demonstrates how to replace placeholders with data specified as an object. When the Insert Date button is clicked, the DateNow and TimeNow placeholders are replaced using the ASPxHtmlEditor.ReplacePlaceholders method's ReplacePlaceholders(string html, object placeholders) overload.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/aspxhtmleditor-how-to-specify-placeholders-using-dictionary-and-object-structures-t283576
<dx:ASPxHtmlEditor ID="HtmlEditor" ClientInstanceName="HtmlEditor" runat="server">
<Toolbars>
<dx:HtmlEditorToolbar>
<Items>
<dx:ToolbarUndoButton>
</dx:ToolbarUndoButton>
<dx:ToolbarRedoButton>
</dx:ToolbarRedoButton>
<dx:ToolbarBoldButton BeginGroup="True">
</dx:ToolbarBoldButton>
<dx:ToolbarItalicButton>
</dx:ToolbarItalicButton>
<dx:ToolbarUnderlineButton>
</dx:ToolbarUnderlineButton>
<dx:ToolbarStrikethroughButton>
</dx:ToolbarStrikethroughButton>
<dx:ToolbarJustifyLeftButton BeginGroup="True">
</dx:ToolbarJustifyLeftButton>
<dx:ToolbarJustifyCenterButton>
</dx:ToolbarJustifyCenterButton>
<dx:ToolbarJustifyRightButton>
</dx:ToolbarJustifyRightButton>
<dx:ToolbarInsertPlaceholderDialogButton>
</dx:ToolbarInsertPlaceholderDialogButton>
</Items>
</dx:HtmlEditorToolbar>
</Toolbars>
<Placeholders>
<dx:HtmlEditorPlaceholderItem Value="DateNow" />
<dx:HtmlEditorPlaceholderItem Value="TimeNow" />
<dx:HtmlEditorPlaceholderItem Value="FirstName" />
<dx:HtmlEditorPlaceholderItem Value="LastName" />
</Placeholders>
</dx:ASPxHtmlEditor>
<dx:ASPxButton ID="SignatureButton" runat="server" OnClick="Insert_Signature"
Text="Insert Signature"></dx:ASPxButton>
<dx:ASPxButton ID="DateButton" runat="server" OnClick="Insert_Date" Text="Insert Date">
</dx:ASPxButton>
private class PlaceholdersForDate {
private DateTime date = DateTime.Now;
private string formatDate = "d MMM yyyy";
private string formatTime = "HH:mm";
public string DateNow {
get {
return date.ToString(formatDate);
}
}
public string TimeNow {
get {
return date.ToString(formatTime);
}
}
}
// Replaces placeholders specified as an object
protected void Insert_Date(object sender, EventArgs e) {
PlaceholdersForDate placeholdersForDate = new PlaceholdersForDate();
string html = HtmlEditor.Html;
string newHtml = ASPxHtmlEditor.ReplacePlaceholders(html, placeholdersForDate);
HtmlEditor.Html = newHtml;
}
<dx:ASPxHtmlEditor ID="HtmlEditor" ClientInstanceName="HtmlEditor" runat="server">
<Toolbars>
<dx:HtmlEditorToolbar>
<Items>
<dx:ToolbarUndoButton>
</dx:ToolbarUndoButton>
<dx:ToolbarRedoButton>
</dx:ToolbarRedoButton>
<dx:ToolbarBoldButton BeginGroup="True">
</dx:ToolbarBoldButton>
<dx:ToolbarItalicButton>
</dx:ToolbarItalicButton>
<dx:ToolbarUnderlineButton>
</dx:ToolbarUnderlineButton>
<dx:ToolbarStrikethroughButton>
</dx:ToolbarStrikethroughButton>
<dx:ToolbarJustifyLeftButton BeginGroup="True">
</dx:ToolbarJustifyLeftButton>
<dx:ToolbarJustifyCenterButton>
</dx:ToolbarJustifyCenterButton>
<dx:ToolbarJustifyRightButton>
</dx:ToolbarJustifyRightButton>
<dx:ToolbarInsertPlaceholderDialogButton>
</dx:ToolbarInsertPlaceholderDialogButton>
</Items>
</dx:HtmlEditorToolbar>
</Toolbars>
<Placeholders>
<dx:HtmlEditorPlaceholderItem Value="DateNow" />
<dx:HtmlEditorPlaceholderItem Value="TimeNow" />
<dx:HtmlEditorPlaceholderItem Value="FirstName" />
<dx:HtmlEditorPlaceholderItem Value="LastName" />
</Placeholders>
</dx:ASPxHtmlEditor>
<dx:ASPxButton ID="SignatureButton" runat="server" OnClick="Insert_Signature"
Text="Insert Signature"></dx:ASPxButton>
<dx:ASPxButton ID="DateButton" runat="server" OnClick="Insert_Date" Text="Insert Date">
</dx:ASPxButton>
Private Class PlaceholdersForDate
Private [date] As Date = Date.Now
Private formatDate As String = "d MMM yyyy"
Private formatTime As String = "HH:mm"
Public ReadOnly Property DateNow() As String
Get
Return [date].ToString(formatDate)
End Get
End Property
Public ReadOnly Property TimeNow() As String
Get
Return [date].ToString(formatTime)
End Get
End Property
End Class
' Replaces placeholders specified as an object
Protected Sub Insert_Date(ByVal sender As Object, ByVal e As EventArgs)
Dim placeholdersForDate As New PlaceholdersForDate()
Dim html As String = HtmlEditor.Html
Dim newHtml As String = ASPxHtmlEditor.ReplacePlaceholders(html, placeholdersForDate)
HtmlEditor.Html = newHtml
End Sub