Wednesday, August 3, 2011

load image or captcha image using jquery and

Demo for show image or catptch image on button click using jquery........

<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script language="javascript" >
$(document).ready(function () {
$("#btnload").click(function () {
$.get("data.ashx", function (data) {



<img id="imgload" border="0" src="" /> <br />
<button id="btnload">Load Image</button>

<%@ WebHandler Language="C#" %>

using System;
using System.Drawing;
using System.Web;
using System.Drawing.Imaging;
using System.IO;
public class data : IHttpHandler
public void ProcessRequest(HttpContext context)
context.Response.ContentType = "text/plain";
Bitmap bmp = new Bitmap(context.Server.MapPath("download.jpg"));
using (MemoryStream ms = new MemoryStream())
// Convert Image to byte[]
bmp.Save(ms, ImageFormat.Jpeg);
byte[] imageBytes = ms.ToArray();

// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
context.Response.Write("data:image/gif;base64," + base64String);

public bool IsReusable
return false;

No comments :

Post a Comment

AJAX, asp,, and sql server security, IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath