# 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 handler, and the Page_Load event configures the output, returning the completed result as a PDF.

- **Author:** Bjoern Meyer
- **Published:** 2020-01-01
- **Modified:** 2026-03-05
- **Description:** 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 handler, and the Page_Load event configures the output, returning the completed result as a PDF.
- **4 min read** (614 words)
- **Tags:**
  - ASP.NET
  - HTML5
  - Reporting
  - Tutorial
- **LLMs.txt URL:** https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt
- **LLMs-full.txt URL:** https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms-full.txt
- **Canonical URL:** https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/

---

Create Your Application
-----------------------

1. Open Visual Studio and create a new *ASP.NET Empty Web Application*.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_1.webp "image")
2. In the *Solution Explorer*, select the project and choose *Add New Item...* from the *Project* main menu.
    
    In the opened dialog *Add New Item*, select *Web Form* and confirm with *Add*.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_2.webp "image")
3. In the *Solution Explorer*, select the newly created *Web Form* and choose *Component Designer* from the *View* main menu.
    
    Find the **MailMerge** component in the *Toolbox* and drag and drop an instance onto the *Component Designer* form.
    
    Repeat this step with the **ServerTextControl** component.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_3.webp "image")
4. Select the **MailMerge** component and set the *TextComponent* property to *serverTextControl1* - the name of the inserted instance of *ServerTextControl*.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_4.webp "image")
5. While the project is selected in the *Solution Explorer*, choose *Add Existing Item...* from the *Project* main menu.
    
    In the opened dialog *Add Existing Item*, browse to the following sample folder:
    
    *%USERPROFILE%\\Documents\\TX Text Control 29.0.NET Server for ASP.NET\\Samples\\ASP.NET\\CSharp\\Documentation Tutorials\\MailMerge\\Tutorial*
    
    or
    
    *%USERPROFILE%\\Documents\\TX Text Control 29.0.NET Server for ASP.NET\\Samples\\ASP.NET\\VB.NET\\Documentation Tutorials\\MailMerge\\Tutorial*
    
    Select the following 2 files: **template.docx** and **sample\_db.xml** and click the *Add* button.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_5.webp "image")
6. Select the *Web Form* in the *Solution Explorer* and choose *Designer* from the *View* main menu.
    
    Find the **Button** control in the *Toolbox* and drag and drop an instance onto the *Web Form*.
    
    ![image](https://s1-www.textcontrol.com/assets/dist/blog/2020/01/01/g/assets/tutorial_aspnet_reporting_6.webp "image")
7. Double-click the button and insert the following code to the event handler:
    
    ```
    protected void Button1_Click(object sender, EventArgs e)
    {
    // create a DataSet from the sample XML data source
    System.Data.DataSet ds = new System.Data.DataSet();
    ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto);
    
    // load the template
    mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
    TXTextControl.DocumentServer.FileFormat.WordprocessingML);
    
    // merge the template with data
    mailMerge1.Merge(ds.Tables[0]);
    
    // save the document as PDF into a byte array
    byte[] data;
    mailMerge1.SaveDocumentToMemory(out data,
    TXTextControl.BinaryStreamType.AdobePDF, null);
    
    // return the document to the browser for download
    Response.Clear();
    Response.AddHeader("content-disposition",
    String.Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"));
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(data);
    Response.End();
    }
    ```
    
     ```
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
    ' create a DataSet from the sample XML data source
    Dim ds As New System.Data.DataSet()
    ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto)
    
    ' load the template
    mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
    TXTextControl.DocumentServer.FileFormat.WordprocessingML)
    
    ' merge the template with data
    mailMerge1.Merge(ds.Tables(0))
    
    ' save the document as PDF into a byte array
    Dim data As Byte()
    mailMerge1.SaveDocumentToMemory(data,
    TXTextControl.BinaryStreamType.AdobePDF, Nothing)
    
    ' return the document to the browser for download
    Response.Clear()
    Response.AddHeader("content-disposition",
    [String].Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"))
    Response.ContentType = "application/pdf"
    Response.BinaryWrite(data)
    Response.[End]()
    End Sub
    ```
8. In the same code view, add the following code to the **Page\_Load** event:
    
    ```
    protected void Page_Load(object sender, EventArgs e)
    {
    InitializeComponent();
    }
    ```
    
     ```
    Protected Sub Page_Load(sender As Object, e As EventArgs)
    InitializeComponent()
    End Sub
    ```
9. Compile and start the application. Press the button to create the report that is returned as a PDF file.

---

## 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

- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/llms.txt)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Automatically Reconnect to the Server and Recover the Document](https://www.textcontrol.com/blog/2019/09/05/automatically-reconnect-to-the-server-and-recover-the-document/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [ASP.NET MVC: Implementing a Simplistic, Custom Button Bar](https://www.textcontrol.com/blog/2017/03/13/aspnet-mvc-implementing-a-simplistic-custom-button-bar/llms.txt)
- [ASP.NET MVC: Adding Protected Sections to Documents](https://www.textcontrol.com/blog/2017/03/01/aspnet-mvc-adding-protected-sections-to-documents/llms.txt)
- [ASP.NET: Adding Electronic Signatures to Documents](https://www.textcontrol.com/blog/2016/10/12/aspnet-adding-electronic-signatures-to-documents/llms.txt)
- [HTML5: Display and Handle FormCheckBox Fields](https://www.textcontrol.com/blog/2015/09/22/html5-display-and-handle-formcheckbox-fields/llms.txt)
- [Merging Documents with RESTful Web API's](https://www.textcontrol.com/blog/2015/07/31/merging-documents-with-restful-web-apis/llms.txt)
- [TextControl.Web: Creating an MVC Application with Razor](https://www.textcontrol.com/blog/2015/05/12/textcontrolweb-creating-an-mvc-application-with-razor/llms.txt)
- [Reporting Best Practices and How-To Guides](https://www.textcontrol.com/blog/2015/02/05/reporting-best-practices-and-how-to-guides/llms.txt)
- [HTML5 Technical Considerations - The Concept Explained](https://www.textcontrol.com/blog/2014/10/16/html5-technical-considerations-the-concept-explained/llms.txt)
- [TX Text Control Web: Attaching Events to Ribbon Elements](https://www.textcontrol.com/blog/2014/10/07/tx-text-control-web-attaching-events-to-ribbon-elements/llms.txt)
- [TX Text Control Web: Customize the Ribbon Bar](https://www.textcontrol.com/blog/2014/10/03/tx-text-control-web-customize-the-ribbon-bar/llms.txt)
- [.NET C# PDF Generation Techniques: Which Method is Right for Your Project?](https://www.textcontrol.com/blog/2024/10/30/net-csharp-pdf-generation-techniques-which-method-is-right-for-your-project/llms.txt)
- [Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications](https://www.textcontrol.com/blog/2024/07/30/best-practices-for-mail-merge-and-form-field-processing-in-asp-net-core-csharp-applications/llms.txt)
- [Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF Template Engines in .NET C#](https://www.textcontrol.com/blog/2024/07/29/advantages-of-flow-type-layout-reporting-vs-banded-reporting-or-pdf-template-engines-in-net-c-sharp/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [TX Text Control 32.0 Has Been Released](https://www.textcontrol.com/blog/2023/09/13/tx-text-control-320-has-been-released/llms.txt)
- [TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released](https://www.textcontrol.com/blog/2022/09/07/tx-text-control-31-released/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [TX Text Control 30.0 and TX Spell .NET 9.0 Have Been Released](https://www.textcontrol.com/blog/2021/11/29/tx-text-control-30-released/llms.txt)
- [Detect Toggle Button Changes Using a MutationObserver](https://www.textcontrol.com/blog/2021/11/11/detect-toggle-button-changes-using-a-mutationobserver/llms.txt)
