ASP.NET: Generate QR code image using Google Chart API

In this article I am going to explain how to generate QR code image using Google Chart API in asp.net.


Description:
QR code image will be generating using Google chart API with a url get request.


Implementation:
HTML Markup:
<fieldset style="width:30%">
        <legend>Generate QR Code using Google API</legend>
        <table>
        <tr><td>Enter URL OR Text:</td><td><asp:TextBox ID="txturl" runat="server"></asp:TextBox></td></tr>
        <tr><td colspan="2"><asp:Image runat="server" ID="QRImage"/></td></tr>

        <tr><td></td><td></td></tr>
        <tr><td></td><td><asp:Button ID="btnsubmit" runat="server" Text="Generate QR Code" onclick="btnsubmit_Click" /></td></tr>
        </table>
        </fieldset>

Generate QR code
On Button click write the below given code.
C# code:
protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            var url = "http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=" + txturl.Text + "";
            QRImage.ImageUrl = url;
        }
        catch(Exception ex)
        {
        }
    }

VB.net Code:
Protected Sub btnsubmit_Click(sender As Object, e As System.EventArgs) Handles btnsubmit.Click
        Try
            Dim url = "http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=" + txturl.Text + ""
            QRImage.ImageUrl = url
        Catch ex As Exception
        End Try
    End Sub


Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

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