How To: Barcode Professional SDK in ASP.NET Web Applications
Product Barcode Professional SDK for .NET Published 05/12/2008 Updated 05/12/2008
Overview
This walkthrough illustrates how easily you can use Barcode Professional SDK for .NET in ASP.NET Web Applications. During the course of this walkthrough, you will accomplish the following activities:
- Create an ASP.NET Web Site using Visual Studio 2008 or VWD 2008 Express Edition.
- Create a simple ASP.NET WebForm (ASPX) to dynamically generate barcodes.
- Create an ASP.NET HTTP Handler (ASHX) for barcode generation by leveraging Barcode Professional SDK for .NET
Requirements
Neodynamic Barcode Professional SDK for .NET
Microsoft .NET Framework 3.5 (ASP.NET 3.5) or greater
Microsoft Visual Studio 2008
Microsoft Visual Web Developer 2008 Express Edition (VWD)
Follow up these steps
- Ensure you have installed Barcode Professional SDK for .NET
- Launch Visual Studio 2008 or VWD 2008 and create a new ASP.NET Web Site
- Add a reference to Barcode Professional SDK for .NET assembly (Neodynamic.SDK.Barcode.dll)
- Open Default.ASPX file at design time and in the Source View paste the following content:
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Barcode Professional SDK in ASP.NET</title> <style type="text/css"> .newStyle1 { font-family: arial, Helvetica, sans-serif; } </style> </head> <body> <form id="form1" runat="server"> <div class="newStyle1"> <h3>Barcode Professional SDK in ASP.NET</h3> <br /> Enter Value to Encode: <br /> <asp:TextBox ID="TextBox1" runat="server" Width="264px"> </asp:TextBox><asp:Button ID="Button1" runat="server" Text="Barcode Now!" onclick="Button1_Click" /> <br /> <br /> <asp:Image ID="Image1" runat="server" Visible="false" /> </div> </form> </body> </html> -
In Design View, double click on "Barcode Now!" button and paste the following code in the Button's Click event handler:
VB
If (Me.TextBox1.Text.Length > 0) Then Me.Image1.ImageUrl = "~/BarcodeGen.ashx?code=" + Me.TextBox1.Text Me.Image1.Visible = True End IfC#
if (this.TextBox1.Text.Length > 0) { this.Image1.ImageUrl = "~/BarcodeGen.ashx?code=" + this.TextBox1.Text; this.Image1.Visible = true; } -
Add a new item of type "Generic Handler" and name it BarcodeGen.ASHX. In this ASP.NET Handler, we'll create an instance of BarcodeProfessional class for barcode generation. As you'll realize, the code is very simple and straightforward. So after file creation, open it and paste the following code:
VB
<%@ WebHandler Language="VB" Class="BarcodeGen" %> Imports System Imports System.Web Imports Neodynamic.SDK Public Class BarcodeGen : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 'Get value to encode from querystring Dim valueToEncode As String = context.Request("code") 'Create BarcodeProfessional object Dim bc As New BarcodeProfessional() 'Set barcode standard bc.Symbology = Symbology.Code128 'Set value to encode bc.Code = valueToEncode 'Generate barcode context.Response.ContentType = "image/gif" context.Response.BinaryWrite(bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif)) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End ClassC#
<%@ WebHandler Language="C#" Class="BarcodeGen" %> using System; using System.Web; using Neodynamic.SDK; public class BarcodeGen : IHttpHandler { public void ProcessRequest (HttpContext context) { //Get value to encode from querystring string valueToEncode = context.Request["code"]; //Create BarcodeProfessional object BarcodeProfessional bc = new BarcodeProfessional(); //Set barcode standard bc.Symbology = Symbology.Code128; //Set value to encode bc.Code = valueToEncode; //Generate barcode context.Response.ContentType = "image/gif"; context.Response.BinaryWrite(bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif)); } public bool IsReusable { get { return false; } } } -
That's it. Run your project from VS. You'll get something like the following figure:

Barcode Professional SDK in ASP.NET Web Applications (Internet Explorer Browser)

Barcode Professional SDK in ASP.NET Web Applications (Mozilla Firefox Browser)
Sample Files Download
Here are the VB.NET and C# versions of this sample. Please download the zip file and extract it.- For Visual Basic.NET: BarcodeSDKSampleASPNETVB.zip (120 KB)
- For Visual C#.NET: BarcodeSDKSampleASPNETCS.zip (120 KB)
Useful? Share it!
| Tweet |
|
Related Articles
How to print images, pictures, texts and high quality barcodes using VB.NET or C#How to create local reports RDLC featuring barcode images in .NET SDK
How to create Crystal Reports featuring barcode images using Typed DataSet in .NET SDK
Need help? Contact Support
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.