Simple Approach for QR Code Generation in ASP.Net using Google API
Though there are many solutions for QR Code generation in ASP.Net, all of it requires referring to 3rd party dlls. But there is a very simple alternative through which we can create a QR code generator in ASP.Net within minutes without referring to any 3rd party dlls.
Let's create a ASP.Net web application with a text box, image control and Button as shown:
- <asp:TextBox runat="server" ID="txtData"></asp:TextBox>
- <asp:Button runat="server" ID="btnClickMe" Text="Click Me" OnClick="btnClickMe_Click" />
- <br />
- <asp:Image runat="server" ID="ImgQrCode" Height="160" Width="160" />
In the button click event, generate the URL for the API with the data entered in the text box and size of the image control and set it to the image control's image URL property
- protected void btnClickMe_Click(object sender, EventArgs e)
- {
- ImgQrCode.ImageUrl = "https://chart.googleapis.com/chart? cht=qr&chl=" + WebUtility.HtmlEncode(txtData.Text) + "&choe=UTF-8&chs=" + ImgQrCode.Height.ToString().Replace("px", "") + "x" + ImgQrCode.Width.ToString().Replace("px", "");
- }
Result
That's it.
More details in the following
link.