TextControl.Web: Custom Mail Merge Preview
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.…

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
This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.
Automatically Reconnect to the Server and Recover the Document
We just published a sample project that shows how to reconnect to the server and how to recover the current document.
JavaScript API: Working with Merge Fields
This article gives an overview of how to add, remove and manipulate merge fields programmatically using the JavaScript API.
Technology Preview: Embeddable HTML Widget to integrate Document Editing to…
This technology preview shows an early version of an HTML widget that can be embedded into any HTML page.
Embedding TXTextControl.Web in non-.NET Framework applications like .NET…
This article shows how to embed the ASP.NET MVC component TXTextControl.Web into non-.NET Framework applications.