TextControl.Web: Custom Mail Merge Preview
Override the default Preview Merge Results button in Web.TextControl by cloning its DOM node with jQuery to strip anonymous JavaScript event handlers, then rewiring custom click behavior. This technique works where standard ribbon button event cancellation fails due to inline handlers.

In a recent blog entry, we explained how to add custom code to ribbon buttons and how to cancel the event bubbling. This works for the majority of buttons, but doesn't work for the Preview Merge Results button, because of an anonymous Javascript function.
In this case, the complete node must be cloned to remove the event handlers. Then, all the required events can be rewired. The following code uses jQuery to store the parent node, clone the button and to append it to the parent element.
<script>
// wait until the complete ribbon is loaded
TXTextControl.addEventListener("ribbonTabsLoaded", function (e) {
attachEvents();
});
function attachEvents() {
// store the parent element
var parent = $("#tglBtnPreviewMergeResults").parent();
// clone and append the element to the parent
$("#tglBtnPreviewMergeResults").clone().appendTo(parent);
// remove the old element
$("#tglBtnPreviewMergeResults").remove();
// rewire required events
$(document).on("click", "#tglBtnPreviewMergeResults",
function () {
alert("Custom Preview");
});
}
</script>
Happy coding!
Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
Creating Your First ASP.NET Reporting Application
The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click…
Automatically Reconnect to the Server and Recover the Document
When a WebSocket connection drops, the TX Text Control editor automatically reconnects and recovers the document using browser local storage. The implementation saves document state client-side…
JavaScript API: Working with Merge Fields
The TX Text Control JavaScript API enables inserting, deleting, and manipulating merge fields in the HTML5-based document editor. Developers create MergeField objects, add them at specific…
Technology Preview: Embeddable HTML Widget to integrate Document Editing to…
TX Text Control offers a technology preview of an embeddable JavaScript widget that adds document editing to Angular, React, and other web frameworks. Developers add a script tag and create a…
Embedding TXTextControl.Web in non-.NET Framework applications like .NET…
The HTML5-based Web.TextControl editor can run inside an IFrame to embed it in non-.NET Framework applications such as .NET Core or AngularJS sites. The hosting page sends structured JSON commands…
