arturoriyadh
New Member
I'm trying to use Javascript to set the ImageUrl attribute of an ASP:Image element. I've dug through well over a dozen guides on this, and they all seem to corroborate my code, but for some reason I cannot get my code to call the Handler. The server-side handler is called 'Handler.ashx', my javascript is in a page called Default.aspxHandler.ashx (This should work fine and not need changed..)\[code\]public class Handler : IHttpHandler {public void ProcessRequest (HttpContext context){ int id; if (context.Request.QueryString["id"] != null) { id = Convert.ToInt32(context.Request.QueryString["id"]); context.Response.ContentType = "image/jpeg"; byte[] bufferImg = GetImage(id); context.Response.OutputStream.Write(bufferImg, 0, bufferImg.Length); }}public byte[] GetImage(int id){ string conn = System.Configuration.ConfigurationManager.ConnectionStrings["WebShoppingConnectionString"].ConnectionString; System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(conn); string sql = "SELECT Picture FROM Tb_AvailableProduct WHERE Prod_ID = @Prod_ID"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, connection); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@Prod_ID", id); try { connection.Open(); return (byte[])cmd.ExecuteScalar(); } .... }`\[/code\]Default.aspx(Presently trying to set the attribute with a button this function. Using a hard-coded id I know is valid, but will be sending a paramater later.)\[code\]function GetImage() { var img = document.getElementById("ProductImage"); img.setAttribute('ImageUrl', 'Handler.ashx?id=429'); //img.src="http://stackoverflow.com/questions/15627397/Handler.ashx?id=429"; //img.ImageUrl = "~/Handler.ashx?id=429";}\[/code\]Also, been trying to do this with the attribute: \[code\]<asp:Image ID="ProductImage" runat="server" ImageUrl="~/Handler.aspx?id=429" Style="z-index: 100; left:700px; position: absolute; top: 13px; width: 415px; height: 251px;" />\[/code\]Basically, I've tried every simple variation of the snippet \[code\]Handler.ashx?id=429\[/code\], from relative to absolute, and NOTHING will even connect to ProcessRequest(). Any ideas??