How to generate barcode in asp.net

In this article I am going to explain how to generate barcode in asp.net.

How to generate barcode in asp.net

Description:
Barcode provides asset and security tracking. To generate the barcode I am using ONbarcodeDLL.

Implementation:
Add a webform to project. Download the Onbacode DLL and add it to project.

HTML markup:
  <fieldset style="width:30%">
        <legend>Generate BAR Code Example</legend>
        <table>
        <tr><td>Enter Text/Value:</td><td><asp:TextBox ID="txtvalue" runat="server"></asp:TextBox></td></tr>       
        <tr><td></td><td><asp:Button ID="btnsubmit"
            runat="server" Text="Generate BAR Code"/></td></tr>
            <tr><td colspan="2"><asp:Image runat="server" ID="imgbarcode" /></td></tr>
        <tr><td></td><td></td></tr>
        </table>
        </fieldset>

Import the namespace

C# Code :
using System.Drawing;
using System.Drawing.Imaging;
using OnBarcode.Barcode;

VB.net code:
Imports OnBarcode.Barcode
Imports System.Drawing
Imports System.Drawing.Imaging

On button click write the below given code:

C# Code
protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            Linear barcode = new Linear();
            barcode.Type = BarcodeType.CODE39;
            barcode.Data = txtvalue.Text;
            barcode.drawBarcode("image/barcode.gif");
            imgbarcode.ImageUrl = "image/barcode.gif";
        }
        catch (Exception ex)
        {
        }
    }


VB.net code:
   Protected Sub btnsubmit_Click(sender As Object, e As EventArgs) Handles btnsubmit.Click
        Try
            Dim barcode As New Linear
            barcode.Type = BarcodeType.CODE39
            barcode.Data = txtvalue.Text
            barcode.drawBarcode("image/barcode.jpg")
            imgbarcode.ImageUrl = "image/barcode.jpg"
        Catch ex As Exception

        End Try
    End Sub

Build and run the project.


Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget