ASP.NET Web Forms Control

Use BarcodeControl to display a barcode on a classic ASP.NET Web Forms page. The control is included in TECIT.TBarCode.dll for .NET Framework applications and is available in the TECIT.TBarCode.Web namespace. It is not an ASP.NET Core control. For ASP.NET Core applications, generate the barcode image with the Barcode Class instead.

Create the Project and Add a Reference

  1. Create or open an ASP.NET Web Forms project that targets .NET Framework 4.5 or later.
  2. Add TECIT.TBarCode.dll to the project, either through the TECIT.TBarCode NuGet package or from the appropriate installation directory.

Add the Control to a Web Form

Register the control namespace near the top of the .aspx file:

<%@ Register Assembly="TECIT.TBarCode"
    Namespace="TECIT.TBarCode.Web"
    TagPrefix="tbc" %>

Add the control inside the page's server-side form:

<tbc:BarcodeControl ID="BarcodeControl1" runat="server"
    Width="320px" Height="120px" />

Configure the Barcode

In the page's C# code-behind file, for example Default.aspx.cs, set the barcode properties. Call Refresh() after changing the data or other barcode properties so that the displayed image is updated:

using System;
using TECIT.TBarCode;

public partial class BarcodePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BarcodeControl1.Barcode.BarcodeType = BarcodeType.DataMatrix;
        BarcodeControl1.Barcode.Data = "Sample barcode data";
        BarcodeControl1.Refresh();
    }
}

By default, the control stores temporary PNG files in the barcodecache directory below the web application. The application account therefore needs write access to that directory. Use the control's CacheDirectory property if the temporary images should be stored in a different directory.

Optimize the Barcode for Printing

For normal display in a browser, no DPI setting is required. If the web page will be printed, set Barcode.Dpi to the printer resolution. The barcode keeps the size specified by Width and Height in the browser, while the generated image uses the higher resolution for sharper printed output:

BarcodeControl1.Barcode.Dpi = 300;
BarcodeControl1.Refresh();

Run the Web Application

Start the application and open the page in a browser. The page displays the configured barcode. Without a valid license, the output can include a demo marker.

API Reference

For all web-control and barcode properties, see the TBarCode .NET Developer Reference. The ASP.NET Web Forms control is documented in the TECIT.TBarCode.Web namespace.

Search documentation

Search in
More scopes
Additional scopes

All contents