Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would do the image loading as a <a href="http://msdn.microsoft.com/en-us/library/46c5ddfy.aspx" rel="nofollow noreferrer">HttpHandler</a>, which has to be registred in web.config. You don't really need Ajax for the image loading. Your javascript code has to change the <code>src</code> attribute of your <code>img</code> tag in order to display a new image.</p> <p>Here's an example of a http handler which loads a blog from a MS SQL db with a query parameter called <code>id</code>.</p> <pre><code>public class IISHandler1 : IHttpHandler { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { int theID; if (!int.TryParse(context.Request.QueryString["id"], out theID)) throw new ArgumentException("No parameter specified"); context.Response.ContentType = "image/jpeg"; // or gif/png depending on what type of image you have Stream strm = DisplayImage(theID); byte[] buffer = new byte[2048]; int byteSeq = strm.Read(buffer, 0, 2048); while (byteSeq &gt; 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 2048); } } public Stream DisplayImage(int theID) { try { SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString()); string sql = "SELECT image FROM Table1 WHERE id = @ID"; using (SqlCommand cmd = new SqlCommand(sql, connection) { CommandType = CommandType.Text }) { cmd.Parameters.AddWithValue("@ID", theID); connection.Open(); object theImg = cmd.ExecuteScalar(); return new MemoryStream((byte[]) theImg); } } catch { return null; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload