My problem is this. When I just have a single parameter to search by, my image control works, when I try and pass a second parameter through, the image control does not work. I am using a generic handler as the image.URL, as I want to be able to either pull the image out of a database, or select one from the drive with which to replace the database copy.
Ok, so after having removed all references to the version (which is the second parameter causing the problem) I have found that this line string version = context.Request.QueryString["Version"].ToString();
in ImageHandler.ashx, is causing the problem.
My code is as follows...
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
TemplateData imgData = null;
string schemeCode = context.Request.QueryString["schemeCode"].ToString();
string version = context.Request.QueryString["Version"].ToString();
if(!String.IsNullOrEmpty(schemeCode)) imgData = DataClass.ReturnData(schemeCode);
if (imgData != null)
{
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(imgData.Logo);
context.Response.OutputStream.Write(imgData.Logo, 0, imgData.Logo.Length);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
The coed behind...
protected void btnSearch_Click(object sender, EventArgs e)
{
if (ddSchemeCode.SelectedIndex > 0)
{
// Existing Data to load from database
TemplateData temp = DataClass.ReturnData(ddSchemeCode.SelectedItem.Text);
if (temp != null)
{
txtVersion.Text = temp.Version;
txtComment.Text = temp.Comment;
txtSchemeCode.Text = temp.SchemeCode;
txtTemplateId.Text = temp.TemplateId;
imgLogo.ImageUrl = String.Format("ImageHandler.ashx?schemeCode={0}", ddSchemeCode.SelectedItem.Text);
}
}
and the ReturnData
medthod...
public static TemplateData ReturnData(string schemeCode)
{
string sqlInstructionCstmID = "SELECT TOP(1) LetterTemplateCustomisationId, TemplateId, Logo, SchemeCode, Version, Comment FROM LetterTemplateCustomisation WHERE SchemeCode ='" + schemeCode + "' ";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["LettersDatabase"].ConnectionString;
SqlConnection connect = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(sqlInstructionCstmID, connect);
command.CommandType = CommandType.Text;
connect.Open();
SqlDataReader dr = command.ExecuteReader();
TemplateData tempData = null;
if (dr.HasRows)
{
dr.Read();
tempData = new TemplateData(dr);
}
dr.Close();
connect.Close();
return tempData;
}
so If I pass an extra parameter into the ReturnData
method, No images appear.
Muchly appreciated guys. Thanks