Description:-
In this article we will generate QRCode from Input Textbox value and store in QRCode. Here we will use Textbox Control and Button Control to Generate QRCode and use QRCode Reference to generate it.
Download file:- QRCoder.dll
Default.aspx:-
Drag Textbox and Button and Placeholder Control in your Webpage.
Default.aspx:-
Drag Textbox and Button and Placeholder Control in your Webpage.
<div> <asp:TextBox ID="txtCode" runat="server"></asp:TextBox> <asp:ButtonID="btnGenerate"runat="server"Text="Generate"OnClick="btnGenerate_Click" /> <hr /> <asp:PlaceHolder ID="plBarCode" runat="server" /> </div>
Default.aspx.cs:-
Now Go to Code behind File and Code for Generate QRCode on button click event.
Now Go to Code behind File and Code for Generate QRCode on button click event.
protected void btnGenerate_Click(object sender, EventArgs e) { string code = txtCode.Text; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 150; imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); } plBarCode.Controls.Add(imgBarCode); } }
Here we will generate image based on
inputted value and display in Placeholder.
Now run your Webpage and input value in textbox to generate QRCode.
Thanks for comments.....