The Mail ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer Namespace
╰ MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services. class is used to merge data into merge fields, image placeholders, merge blocks, barcodes and other reporting elements. By default, MS Word compatible Merge ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer.Fields Namespace
╰ MergeField Class
The MergeField class implements the MS Word specific MERGEFIELD field. and Form ╰ TX Text Control .NET Server for ASP.NET
╰ TXTextControl Namespace
╰ FormField Class
The FormField class is the base class of all form fields. are merged automatically in loaded templates. But consider a template where a hyperlink should be merged with a dynamic website address.
The Template
In the following screenshot, a simple template is created using TX Text Control that consists of 2 merge fields:
- company
- website
The Data Source
The following class is used to create the data source object for this sample merge process:

Pay attention to the Hyperlink class that contains the actual display Text and the Target. The overridden ToString method returns the text, so that without any custom handling, the merge field would contain the display text after the merge process.
After creating an instance of the data source, the MailMerge class is used to merge the data object into the template:

Custom Event Handling
In our custom handling, we want to replace the merge field website with a clickable hyperlink. Therefore, the Field ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer Namespace
╰ MailMerge Class
╰ FieldMerged Event
Occurs when a field has been merged. event is used to inject the custom handling.

The FieldMerged event is triggered for all merged fields. The event not only returns the Mail ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer Namespace
╰ MailMerge.FieldMergedEventArgs Class
╰ MailMergeFieldAdapter Property
Gets or sets a MailMergeFieldAdapter that contains the already merged field. that contains information about the merged field, but gives also access to the actual DataRow that is used to merge data into the current field. In the event handler, we check whether the returned DataRow object is a custom Hyperlink object:

In case, the object is a Hyperlink, a temporary Server ╰ TX Text Control .NET Server for ASP.NET
╰ TXTextControl Namespace
╰ ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications. is used to generate a new hyperlink with the same format (font, color, ...) that is eventually returned to the Merged ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer Namespace
╰ MailMerge.FieldMergedEventArgs Class
╰ MergedField Property
Gets or sets a byte array that contains the complete data of the merged field. property.
In the resulting document, the website merge field is converted into a clickable hypertext link: