I am having trouble using the output cache param in an aspnet 2.0 page directive. I am using a session variable to hold the value of the selected image. It seems that the dynamic control in a datalist, is not working when the output cache is set to true in the page directive. Is there a way to cache the images seperately to avoid using a page directive?
datalist code
" RepeatColumns="6" CellPadding="8" CellSpacing="8" GridLines="Both" SelectedItemStyle-BackColor="#33ff66" OnSelectedIndexChanged="dtlImages_SelectedIndexChanged" OnItemCommand="dtlImages_ItemCommand">
' Runat="server">
' ID="lblDescription" Font-Bold="True" Font-Size="12px" Font-Names="Arial">
code that retrieves the image from the database
protected void Page_Load(object sender, System.EventArgs e) { string strImageID = Request.QueryString["id"];
string wf4uConnect = System.Configuration.ConfigurationManager.ConnectionStrings["wf4uConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection wf4uConn = new System.Data.SqlClient.SqlConnection(wf4uConnect);
System.Data.SqlClient.SqlCommand myCommand = new SqlCommand("Select ImageFile, ImageType from wf4u_ImageThumb Where ImageId =" + strImageID, wf4uConn);
wf4uConn.Open();
SqlDataReader byteReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while ((byteReader.Read()))
{
Response.BinaryWrite((byte [])byteReader.GetValue(0));
Response.ContentType = (string)byteReader.GetValue(1);
}
wf4uConn.Close();
}
I have implemented an http context object to cache the images as they're loaded into the webpage.
public ImageList (string clientName) { HttpContext context = HttpContext.Current;
if((context.Cache["ImageIdList" + clientName] == null))
{
string wf4uConnect = System.Configuration.ConfigurationManager.ConnectionStrings["wf4uConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection wf4uConn = new System.Data.SqlClient.SqlConnection(wf4uConnect);
string queryStr = "SELECT ImageId FROM wf4u_imageThumb WHERE ClientName = @ClientName";
SqlCommand ImageIdComm = new System.Data.SqlClient.SqlCommand(queryStr, wf4uConn);
ImageIdComm.Parameters.Add("@ClientName", SqlDbType.VarChar).Value = clientName;
wf4uConn.Open();
SqlDataReader ImageIdReader = ImageIdComm.ExecuteReader();
if (ImageIdReader.Read())
{
_ImageId = ImageIdReader.GetInt32(0);
_ClientName = ImageIdReader.GetString(1);
context.Cache.Insert("ImageIdList" + clientName, this, null, DateTime.Now.AddSeconds(600), TimeSpan.Zero);
}
wf4uConn.Close();
}
else
{
ImageList list = (ImageList)context.Cache["ImageIdList" + clientName];
_ImageId = list.ImageId;
_ClientName = list.ClientName;
}
}
any suggestions would be welcomed.