Hi,
My issue is that a cached object called from a new page does not display until you refresh the new page (C#).
I have a requirement to pass an image held in an SQL image datatype field into a new window when produced from a button onClick event.
The initial creation of the image is fine, and here's the button HTML using Javascript to force a new page:
The Caching namespace is declared in the .cs file:
And the final part of the onClick event in the Code Behind passes the data into a cache object:
And here's the Code Behind of the new page I do this to retrieve the image from the cache and display it to the user:
So, this is all good except that the user doesn't see the image until they refresh the page...I'm not currently explicitly adding any Cache instructions to the page, should I?
Can I force a refresh or am I just using Cache in error?
If I thought I could use a QueryString, I would, but as I'm dealing with Binary data, I'm a bit unsure of my options...
Any help/thoughts gratefully received.
lastdonuk
My issue is that a cached object called from a new page does not display until you refresh the new page (C#).
I have a requirement to pass an image held in an SQL image datatype field into a new window when produced from a button onClick event.
The initial creation of the image is fine, and here's the button HTML using Javascript to force a new page:
Code:
<asp:ImageButton ID="Photo" BorderStyle="None" runat="server" ImageUrl="~/images/photo.gif" OnClick="Photo_Click" OnClientClick="javascript:popUpWin('PhotoPopUp.aspx','console',525,525);" />
The Caching namespace is declared in the .cs file:
Code:
using System.Web.Caching;
And the final part of the onClick event in the Code Behind passes the data into a cache object:
Code:
conn2.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
byte[] bindata = (byte[])dr.GetValue(0);
Cache["Bindata"] = bindata;
conn2.Close();
And here's the Code Behind of the new page I do this to retrieve the image from the cache and display it to the user:
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using InfoSoftGlobal;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using DataConnection;
using System.Web.Caching;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
public partial class customers_PhotoPopUp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
byte[] i_photo;
if (Cache["Bindata"] == null)
{
noimage.Visible = true;
}
else
{
i_photo = (byte[])Cache["Bindata"];
Response.AddHeader("Content-Type", "image/pjpeg");
Response.BinaryWrite(i_photo);
}
}
}
So, this is all good except that the user doesn't see the image until they refresh the page...I'm not currently explicitly adding any Cache instructions to the page, should I?
Can I force a refresh or am I just using Cache in error?
If I thought I could use a QueryString, I would, but as I'm dealing with Binary data, I'm a bit unsure of my options...
Any help/thoughts gratefully received.
lastdonuk