The MailMerge 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 MergeFields TX Text Control .NET Server for ASP.NET
DocumentServer.Fields Namespace
MergeField Class
The MergeField class implements the MS Word specific MERGEFIELD field.
and FormFields 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

Template in TX Words

The Data Source

The following class is used to create the data source object for this sample merge process:

Loading...

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:

Loading...

Custom Event Handling

In our custom handling, we want to replace the merge field website with a clickable hyperlink. Therefore, the FieldMerged 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.

Loading...

The FieldMerged event is triggered for all merged fields. The event not only returns the MailMergeFieldAdapter 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:

Loading...

In case, the object is a Hyperlink, a temporary ServerTextControl 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 MergedField 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:

Merged Hyperlink