# Rendering Barcode Objects in ASP.NET

> TX Barcode .NET renders barcode images in ASP.NET by using a separate ASPX page that encodes string data and returns it as a binary image stream. The main page references a WebForms Image control whose ImageUrl points to the barcode generator, refreshing on each button click.

- **Author:** Bjoern Meyer
- **Published:** 2015-11-10
- **Modified:** 2026-07-17
- **Description:** TX Barcode .NET renders barcode images in ASP.NET by using a separate ASPX page that encodes string data and returns it as a binary image stream. The main page references a WebForms Image control whose ImageUrl points to the barcode generator, refreshing on each button click.
- **2 min read** (340 words)
- **Tags:**
  - ASP.NET
  - Barcode Windows Forms
  - GitHub
- **Web URL:** https://www.textcontrol.com/blog/2015/11/10/rendering-barcode-objects-in-aspnet/
- **LLMs URL:** https://www.textcontrol.com/blog/2015/11/10/rendering-barcode-objects-in-aspnet/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2015/11/10/rendering-barcode-objects-in-aspnet/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TextControl.Barcode.Web

---

TX Barcode .NET can be used in ASP.NET web applications to render barcode images. This sample shows how to use a WebForms [Image](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image%28v=vs.110%29.aspx) control to render a barcode image that is created code-behind.

![Rendering barcode objects in ASP.NET](https://s1-www.textcontrol.com/assets/dist/blog/2015/11/10/a/assets/barcode_aspx.webp "Rendering barcode objects in ASP.NET")

The ASPX page is very simple and consists of a WebForms *Image* control, a label to show the raw text and a refresh button:

```
<div>
    <asp:Image ID="Barcode1" runat="server" />
    <asp:Label ID="lblBarcodeText" runat="server" Text=""></asp:Label>
    <asp:Button ID="btnRefresh" runat="server" Text="Refresh" />
</div>
```

In the *Page\_Load* event, the current date and time measured in *ticks* is passed as a *QueryString* to the *ImageUrl* property of the *Image* control. The URL is another ASPX page that uses TX Barcode .NET to create the barcode image.

```
protected void Page_Load(object sender, EventArgs e)
{
    // set the barcode text
    string sBarcodeText = DateTime.Now.Ticks.ToString();

    // set the URL to the ASPX page that returns the image data
    Barcode1.ImageUrl = "CreateBarcode.aspx?text=" + sBarcodeText;
    lblBarcodeText.Text = sBarcodeText;
}
```

In the *Page\_Load* event of *CreateBarcode.aspx*, TX Barcode .NET is used to save the encoded string as a barcode image into a *MemoryStream*. This stream is returned using *Response.BinaryWrite*.

```
protected void Page_Load(object sender, EventArgs e)
{
    // create a new TXBarcodeControl
    TXTextControl.Barcode.TXBarcodeControl barcode =
      new TXTextControl.Barcode.TXBarcodeControl();
    barcode.CreateControl();

    // set the barcode type and size
    barcode.BarcodeType = TXTextControl.Barcode.BarcodeType.MicroPDF;
    barcode.UpperTextLength = 40;
    barcode.Width = 500;

    // set the text from the QueryString
    barcode.Text = Request.QueryString["text"];

    // save the barcode to an image MemoryStream
    MemoryStream stream = new MemoryStream();
    barcode.SaveImage(stream, System.Drawing.Imaging.ImageFormat.Png);

    // send back the image
    Response.Clear();
    Response.ContentType = "image/png";
    Response.BinaryWrite(stream.ToArray());
    Response.Flush();
    Response.Close();
    Response.End();
}
```

The HTML image element loads the image data dynamically from the *CreateBarcode.aspx* page. Every time, the *Refresh* button is clicked, the barcode is updated with the current date and time.

Download the sample from GitHub and test it on your own.

---

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

- [Building a TX Text Control Project with GitHub Actions and the Text Control NuGet Feed](https://www.textcontrol.com/blog/2026/02/09/building-a-tx-text-control-project-with-github-actions-and-the-text-control-nuget-feed/llms.txt)
- [Creating an ASP.NET Core Web App with Docker Support and GitHub Packages](https://www.textcontrol.com/blog/2024/01/05/creating-an-asp-net-core-web-app-with-docker-support-and-github-packages/llms.txt)
- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [Preparing Projects for GitHub Actions](https://www.textcontrol.com/blog/2022/06/27/preparing-projects-for-github-actions/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)
- [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)
- [MVC: Loading a Data Source from a View Model](https://www.textcontrol.com/blog/2016/01/29/mvc-loading-a-data-source-from-a-view-model/llms.txt)
- [MVC: Merging Templates in a Controller HttpPost Method](https://www.textcontrol.com/blog/2016/01/19/mvc-merging-templates-in-a-controller-httppost-method/llms.txt)
- [MVC: Loading Files from the Backstage Menu](https://www.textcontrol.com/blog/2016/01/06/mvc-loading-files-from-the-backstage-menu/llms.txt)
- [MVC: Replace the File Menu with a Backstage View Menu](https://www.textcontrol.com/blog/2015/12/30/mvc-replace-the-file-menu-with-a-backstage-view-menu/llms.txt)
- [MVC: Replace the Ribbon Table Menu with a Quick Insert Table Drop-down](https://www.textcontrol.com/blog/2015/12/23/mvc-replace-the-ribbon-table-menu-with-a-quick-insert-table-drop-down/llms.txt)
- [MVC: Arrange a Docked Web.TextControl with a Custom Bar at the Top](https://www.textcontrol.com/blog/2015/12/18/mvc-arrange-a-docked-webtextcontrol-with-a-custom-bar-at-the-top/llms.txt)
- [MVC: Autosave and Restore Documents to and from the Local Browser Storage](https://www.textcontrol.com/blog/2015/12/14/mvc-autosave-and-restore-documents-to-and-from-the-local-browser-storage/llms.txt)
- [MVC: Loading and Saving Documents Through Controller HttpPost Methods](https://www.textcontrol.com/blog/2015/12/08/mvc-loading-and-saving-documents-through-controller-httppost-methods/llms.txt)
- [HTML5: Adding a Download Button to the Ribbon File Menu](https://www.textcontrol.com/blog/2015/10/22/html5-adding-a-download-button-to-the-ribbon-file-menu/llms.txt)
- [HTML5: Make Merge Field Lists Scrollable in the Ribbon Bar](https://www.textcontrol.com/blog/2015/10/16/html5-make-merge-field-lists-scrollable-in-the-ribbon-bar/llms.txt)
- [HTML5: Store Documents Using the Local Browser Storage](https://www.textcontrol.com/blog/2015/10/09/html5-store-documents-using-the-local-browser-storage/llms.txt)
- [HTML5: Saving Documents in an MVC Controller Method](https://www.textcontrol.com/blog/2015/10/01/html5-saving-documents-in-an-mvc-controller-method/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)
- [Reporting: Styling the DocumentViewer for ASP.NET](https://www.textcontrol.com/blog/2015/06/14/reporting-styling-the-documentviewer-for-aspnet/llms.txt)
- [Building a Touch-enabled Button Bar with Javascript](https://www.textcontrol.com/blog/2015/05/27/building-a-touch-enabled-button-bar-with-javascript/llms.txt)
- [MailMerge: Merge Hyperlinks into Merge Fields](https://www.textcontrol.com/blog/2015/05/15/mailmerge-merge-hyperlinks-into-merge-fields/llms.txt)
