# MailMerge: Removing Empty Blocks

> The RemoveEmptyBlocks property introduced in TX Text Control X13 removes content from merge blocks that have no matching data during processing. Setting it to true on the MailMerge instance enables conditional template sections that appear or disappear based on data availability.

- **Author:** Bjoern Meyer
- **Published:** 2016-02-15
- **Modified:** 2026-07-17
- **Description:** The RemoveEmptyBlocks property introduced in TX Text Control X13 removes content from merge blocks that have no matching data during processing. Setting it to true on the MailMerge instance enables conditional template sections that appear or disappear based on data availability.
- **2 min read** (260 words)
- **Tags:**
  - Mail Merge
  - Reporting
- **Web URL:** https://www.textcontrol.com/blog/2016/02/15/mailmerge-removing-empty-blocks/
- **LLMs URL:** https://www.textcontrol.com/blog/2016/02/15/mailmerge-removing-empty-blocks/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2016/02/15/mailmerge-removing-empty-blocks/llms-full.txt

---

In version X13, a new property has been introduced that specifies whether the content of empty merge blocks should be removed from the template or not: [RemoveEmptyBlocks](https://docs.textcontrol.com/textcontrol/asp-dotnet/ref.txtextcontrol.documentserver.mailmerge.removeemptyblocks.property.htm). This can be very helpful for dynamic templates where under specific circumstances, a complete block should be rendered or not.

Consider the following sample class structure that is used as the merge data object:

```
public class Data
{
    public string Field { get; set; }
    public Appendix Appendix { get; set; }
}

public class Appendix
{
    public string Field1 { get; set; }
}
```

The name of the dynamic block in the template is *Appendix* and the master object is *Data*. If the property *Appendix* of the class *Data* has been set to a valid object of type *Appendix*, the block data exists and is merged.

```
Appendix appendix = new Appendix()
{
    Field1 = "Field 1 Text"
};

Data data = new Data() {
    Field = "Field Text",
    Appendix = appendix
};

using (MailMerge mailMerge1 = new MailMerge())
{
    mailMerge1.TextComponent = textControl1;
    mailMerge1.RemoveEmptyBlocks =
        removeEmptyBlocksToolStripMenuItem.Checked;
    mailMerge1.MergeObject(data);
}
```

If the property [RemoveEmptyBlocks](https://docs.textcontrol.com/textcontrol/asp-dotnet/ref.txtextcontrol.documentserver.mailmerge.removeemptyblocks.property.htm) of [MailMerge](
https://docs.textcontrol.com/textcontrol/asp-dotnet/ref.txtextcontrol.documentserver.mailmerge.class.htm) is set to *true* (code line 14) and the merge data is missing (code line 8), the complete block gets removed.

This new concept allows you to create dynamic structures and conditional blocks in a template. Merge blocks are not necessarily blocks that repeat content. Using merge blocks, you can also define a named range of formatted text with data from another object.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [MailMerge Class Settings Explained](https://www.textcontrol.com/blog/2019/12/05/mailmerge-settings-explained/llms.txt)
- [Merge Excel Documents into MailMerge Templates using IncludeText Fields](https://www.textcontrol.com/blog/2019/08/13/merge-excel-documents-into-mailmerge-templates/llms.txt)
- [MailMerge: Conditional Table Cell Colors using Filter Instructions](https://www.textcontrol.com/blog/2019/06/06/mailmerge-conditional-table-cell-colors-using-filter-instructions/llms.txt)
- [MailMerge: Using Filters to Remove Unwanted Rows](https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/llms.txt)
- [MailMerge: Conditional Rendering of Merge Blocks](https://www.textcontrol.com/blog/2018/11/28/mailmerge-conditional-rendering-of-merge-blocks/llms.txt)
- [DataSourceManager: Using the Ready-to-Use Reporting Dialog Boxes](https://www.textcontrol.com/blog/2018/11/27/datasourcemanager-using-the-ready-to-use-reporting-dialog-boxes/llms.txt)
- [Merge Blocks in X16: Filtering, Sorting and Conditional Rendering](https://www.textcontrol.com/blog/2018/11/22/merge-blocks-in-x16-filtering-sorting-and-conditional-rendering/llms.txt)
- [Different Ways to Create Documents using Text Control Products](https://www.textcontrol.com/blog/2017/10/17/ways-to-create-documents-using-text-control-products/llms.txt)
- [ReportingCloud: Uploading Templates Vs. Sending Templates Inside MergeBody](https://www.textcontrol.com/blog/2017/08/02/reportingcloud-uploading-templates-vs-sending-templates-inside-mergebody/llms.txt)
- [MailMerge: Table Headers and Repeating Blocks](https://www.textcontrol.com/blog/2017/08/01/mailmerge-table-headers-and-repeating-blocks/llms.txt)
- [Text Control Provides a Complete Reporting Tool Set to Fulfill Document Work-flow Requirements](https://www.textcontrol.com/blog/2017/05/09/text-control-provides-a-complete-reporting-tool-set-to-fulfill-document-work-flow-requirements/llms.txt)
- [ReportingCloud: Conditional Text Blocks Based on Merge Blocks](https://www.textcontrol.com/blog/2016/11/02/reportingcloud-conditional-text-blocks-based-on-merge-blocks/llms.txt)
- [MailMerge Improvements in X14: Event Arguments and JSON Data Sources](https://www.textcontrol.com/blog/2016/11/01/mailmerge-improvements-in-x14-event-arguments-and-json-data-sources/llms.txt)
- [Web API Test Sandbox Released on ReportingCloud Portal](https://www.textcontrol.com/blog/2016/10/07/web-api-test-sandbox-released-on-reportingcloud-portal/llms.txt)
- [ReportingCloud: New Test Parameter for Document Quota Related Endpoints](https://www.textcontrol.com/blog/2016/10/06/reportingcloud-new-test-parameter-for-document-quota-related-endpoints/llms.txt)
- [ReportingCloud: The MergeData JSON Object Format Explained](https://www.textcontrol.com/blog/2016/10/04/reportingcloud-the-mergedata-json-object-format-explained/llms.txt)
- [Creating Dynamic HTML Forms Using ReportingCloud](https://www.textcontrol.com/blog/2016/09/28/creating-dynamic-html-forms-using-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Creating Reports from QuickBooks or Salesforce Data Sources Using ReportingCloud and CData Cloud Drivers](https://www.textcontrol.com/blog/2016/06/30/creating-reports-from-quickbooks-or-salesforce-data-sources-using-reportingcloud-and-cdata-cloud-drivers/llms.txt)
- [MailMerge: Merging Fields from Child Tables or Related Objects](https://www.textcontrol.com/blog/2016/06/28/mailmerge-merging-fields-from-child-tables-or-related-objects/llms.txt)
- [Preview: JSON Support in MailMerge Version X14 (24.0)](https://www.textcontrol.com/blog/2016/05/18/preview-json-support-in-mailmerge-version-x14-240/llms.txt)
- [MailMerge: The Append Parameter of the Merge Method Explained](https://www.textcontrol.com/blog/2016/04/05/mailmerge-the-append-parameter-of-the-merge-method-explained/llms.txt)
- [MVC: Adding an Electronic Signature to Documents in Web.TextControl](https://www.textcontrol.com/blog/2016/02/18/mvc-adding-an-electronic-signature-to-documents-in-webtextcontrol/llms.txt)
- [MailMerge: Merge, MergeObject and MergeObjects - When to Use What?](https://www.textcontrol.com/blog/2016/02/16/mailmerge-merge-mergeobject-and-mergeobjects-when-to-use-what/llms.txt)
- [Easy-to-use Sample Templates with Sample XML Data Files](https://www.textcontrol.com/blog/2016/02/10/easy-to-use-sample-templates-with-sample-xml-data-files/llms.txt)
