Create an ASP.NET Framework application to print barcode on web page
In the following step-by-step C# tutorial, we will create a new ASP.NET framework web application to generate, print QR Code, Code 128 and other barcodes on the
web page using Visual Studio 2022.
In the end of the ASP.NET tutorial, you can create and print barcodes on the ASP.NET web page in browser.
1. Create a new ASP.NET framework project
Create a new ASP.NET Web Application (.NET Framework) project in Visual Studio 2022.
Input Project name as BarcodeLib.BarcodeGenerator.ASPNETFrameworkDemo, and choose Framework as .NET Framework 4.7.2
Choose an Empty asp.net web application.
Now a new ASP.NET web application with default files are generated.
2. Add C# Barcode Library dll to the project
Here we will add BarcodeLib C# Barcode Generator for ASP.NET dll to the new web project.
Add downloaded dll BarcodeLib.Barcode.ASP.NET.dll (.net framework 4.0 version from folder /Dll/net40) to the ASP.NET project reference.
3. Create, customize web control on the ASP.NET web form
Add a new aspx Web Form item to the project, named Default.aspx
Replace the following content on file Default.aspx.
Here we have added three aspx controls on the web form:
a text box (ID: tbBarcodeData); a button (ID: btnBarcodeCreate);
an image control (ID: imgBarcode).
4. Add barcode generation C# code to the ASPX cs file
Replace the following content on file Default.aspx.cs. In the following C# code, we will create a Code 128 barcode image with the user input text,
and print the generated barcode image on the web form.
Now we can run the web application in Visual Studio, and generate, print barcodes on the web page in browser.
Create Barcode Image in ASP.NET Web Application in C#
Install
Add Reference BarcodeLib.Barcode.ASP.NET.dll component to your asp.net website project reference.
Implement
Here is the Visual C#.NET sample code for you to generate QR Code barcode images in C# Class Library. Please to your Visual Studio ASP.NET web applications for a barcoding test.
// generate barcode and output to Bitmap object Bitmap barcodeInBitmap = barcode.drawBarcode();
// generate barcode and output to HttpResponse object HttpResponse response = ...; barcode.drawBarcode(response);
// generate barcode and output to Stream object Stream stream = ...; barcode.drawBarcode(stream);
Other Methods to Create Barcodes in C# ASP.NET
Stream Barcodes with Buildin ASP.NET Barcode Application
Developers can stream barcode images with Buildin ASP.NET Barcode Application. Using this method you can create barcodes with a single URL through Microsoft Internet Information Service (IIS). Generated barcode images can be saved for future use, and you just need to pass the url to img tag.