So it seems bit difficult to solve but still i have done it myself:
Here are the working codes:
Handler:
public class imHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string strConn = "//connection string ";
SqlConnection con = new SqlConnection(strConn);
con.Open();
if (context.Request.QueryString["pid"] != null)
{
string ID = context.Request.QueryString["pid"].ToString();
int pid = Convert.ToInt32(ID);
string st = "select image1 from table1 where Row_id=@row";
SqlCommand cmd = new SqlCommand(st, con);
cmd.Parameters.Add("@row", SqlDbType.Int).Value = pid;
cmd.Prepare();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
try
{
context.Response.ContentType = "jpeg";
context.Response.BinaryWrite((byte[])dr["image1"]);
dr.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
}
public bool IsReusable
{
get {
return false;
}
}
}
And here's how to call the images, i have written them in page_
load event u can use btn_click also!!!
Take image controls in ur page and write the codes below:
protected void Page_Load(object sender, EventArgs e)
{
image1.imageurl="handlername.ashx?pid=1";
image2.imageurl="handler.ashx?pid=2";
}
the pid here is the variable u have declared in the handler