How to add barcoding support to ASP.NET Mobile websites (VB.NET and C#)

Prerequisites
– Neodynamic Barcode Professional 5.0 (or greater) for ASP.NET (WebControl)
– Microsoft .NET Framework 2.0 (or greater)
– Microsoft Visual Studio 2005/2008, Visual Web Developer Express Edition or Microsoft Expression Web

Barcode Professional for ASP.NET Mobile technology lets you to easily create Mobile WebForms for displaying barcodes on Mobile Devices supporting XHTML-MP/C-HTML or WAP/WML standards.

In the following Step-By-Step Guide we’re going to create a simple ASP.NET Mobile web page which lets you to display barcodes on Internet Browsers of Mobile Devices leveraging Barcode Professional for ASP.NET and ASP.NET Mobile framework.

Please follow these steps:
– Open your preferred ASP.NET Editor (Microsoft Visual Studio 2005/2008, Visual Web Developer Express Edition or Microsoft Expression Web) and create an ASP.NET website.
– Add a reference to Neodynamic.WebControls.BarcodeProfessional.dll assembly.
– Open the web.config file and add the following entry under httpHandlers node:

<configuration>
<system.web>
<httpHandlers>
<add verb=”*” path=”BarcodeGen.axd” type=”Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional, Neodynamic.WebControls.BarcodeProfessional”/>
</httpHandlers>
</system.web>
</configuration>

– Add a new “Mobile Web Form” item to your project and design it to look like the following figure or copy and paste the markup code in the Source View.


A Mobile WebForm for displaying barcodes

<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”MobileVB.aspx.vb” Inherits=”MobileVB” %>
<%@ Register TagPrefix=”mobile” Namespace=”System.Web.UI.MobileControls” Assembly=”System.Web.Mobile” %>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<body>
<mobile:Form id=”Form1″ runat=”server”><mobile:Label ID=”Label1″ Runat=”server”>Barcode Gen</mobile:Label> <mobile:Image
ID=”Image1″ Runat=”server” Visible=”False”>
</mobile:Image> <mobile:Label ID=”Label2″ Runat=”server”>Value To Encode:</mobile:Label> <mobile:TextBox
ID=”TextBox1″ Runat=”server”>
</mobile:TextBox><mobile:SelectionList ID=”SelectionList1″ Runat=”server” SelectType=”Radio”>
<Item Selected=”True” Text=”Code128″ Value=”Code128″ />
<Item Text=”DataMatrix” Value=”DataMatrix” />
<Item Text=”AztecCode” Value=”AztecCode” />
<Item Text=”QRCode” Value=”QRCode” />
</mobile:SelectionList> <mobile:Command ID=”Command1″ Runat=”server” OnClick=”Command1_Click”>Barcode Now</mobile:Command></mobile:Form>
</body>
</html>

– Now code the button’s click event. In the button’s click event procedure we are going to generate a fixed URL barcode which in Barcode Professional is called “Codeless Barcode Generation” which automatically will detect the current mobile device’s preferred image format for render the barcode image in that format (including Wireless Bitmap WBMP in WAP/WML).

Visual Basic .NET
Protected Sub Command1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Command1.Click
‘Use Codeless barcode generation…
‘ – Please refer to web.config under HttpHanlder node for BarcodeGen settings
‘ – Please refer to “Codeless Barcode Generation” topic of product help for further details about params.

Dim barcodeSymbology As String = Me.SelectionList1.Selection.Value

Me.Image1.ImageUrl = “~/BarcodeGen.axd?S=” + barcodeSymbology + “&C=” + Server.HtmlEncode(Me.TextBox1.Text) + “&BH=0.2&MS=0.04”
Me.Image1.Visible = True
End Sub

Visual C# .NET
protected void Command1_Click(object sender, EventArgs e)
{
//Use Codeless barcode generation…
// – Please refer to web.config under HttpHanlder node for BarcodeGen settings
// – Please refer to “Codeless Barcode Generation” topic of product help for further details about params.

string barcodeSymbology = this.SelectionList1.Selection.Value;

this.Image1.ImageUrl = “~/BarcodeGen.axd?S=” + barcodeSymbology + “&C=” + Server.HtmlEncode(this.TextBox1.Text) + “&BH=0.2&MS=0.04”;
this.Image1.Visible = true;
}

– That’s it. Build your project and test it from some Mobile Device Browser.

Remember to download and install Barcode Professional for ASP.NET in order to reproduce this sample demo.

Links:
This Demo
More Demos
Download Barcode Professional for ASP.NET
More Information about Neodynamic Barcode Professional for ASP.NET

Neodynamic
.NET Components & Controls
http://www.neodynamic.com
http://www.barcode-for-aspnet.com