I have an image control on an aspx page such as
<asp:Image ID="Image1" runat="server" Height="64px" Width="64px" ImageUrl='<%# "SideImageHandler.ashx?ID=" + Eval("ID")%>'/>
And my image handler code is as follows
public void ProcessRequest(HttpContext context) { SqlConnection con = new SqlConnection(); con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["GalleryConnectionString"].ConnectionString; // Create SQL Command Utility.ImageID = 2; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT IMAGE FROM Icon WHERE (ID ="+ Utility.ImageID+")"; cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = con; SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int); ImageID.Value = context.Request.QueryString["ID"]; cmd.Parameters.Add(ImageID); con.Open(); SqlDataReader dReader = cmd.ExecuteReader(); dReader.Read(); context.Response.BinaryWrite((byte[])dReader["IMAGE"]); dReader.Close(); con.Close(); }
But it does not show me the image. What is happening to him?
In addition, I have a download button, when the user clicks on it, the image will be downloaded. I'm new, donβt know what code I put on the download button click event? I ask you to notify me in advance
buddy
source share