MdotButler
Programmer
I have a page that contains an IFrame which I use to display PDF reports that are stored in a database. The process is to obtain the PDF from the database, write it to a file and then set the IFrame source property to display it.
The problem is that it works on the initial image but will not refresh when the src property is set to another file. I created a test form using the nwind database and JPG images. BTW the process works in debug mode from within VS 2008 but fails when uploaded to the IIS server.
aspx code
code behind
TIA
Mark
The problem is that it works on the initial image but will not refresh when the src property is set to another file. I created a test form using the nwind database and JPG images. BTW the process works in debug mode from within VS 2008 but fails when uploaded to the IIS server.
aspx code
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="IFrame_1.aspx.vb" Inherits="IFrame_1" Title="Test IFrame Refresh" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Test IFrame Refresh</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button5" runat="server" OnClick="Button5_Click" Text="1.JPG" />
<asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="2.JPG" />
Using OnClick, writing DB image to disk to display
<br /><br />
<iframe id="ifrReport" runat="server" width="700px" height="800px" style="z-index: -1" />
</div>
</form>
</body>
</html>
code behind
Code:
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Partial Class IFrame_1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Response.CacheControl = "no-cache"
'Response.AddHeader("Pragma", "no-cache")
'Response.Expires = -1
End Sub
'======================================================
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs)
DisplayImage(5)
End Sub
'======================================================
Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs)
DisplayImage(6)
End Sub
'======================================================
Protected Sub DisplayImage(ByVal intRecno As Integer)
Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("~/App_Data/nwind.mdb"))
Dim strSqlCommand As String = "SELECT Photo FROM Employees WHERE EmployeeID = " + CStr(intRecno)
Dim myAdapter As New OleDbDataAdapter(strSqlCommand, myConnection)
Dim myDataSet As New DataSet
myAdapter.Fill(myDataSet, "Employee")
Dim myDataRow As DataRow = myDataSet.Tables("Employee").Rows(0)
' build file and set iframe source
Dim strFileName As String = MapPath("~/Uploads/") + "123.jpg"
If File.Exists(strFileName) Then
File.Delete(strFileName)
End If
Dim arrFile As Byte() = myDataRow("Photo")
Dim binWriter As New BinaryWriter(File.Open(strFileName, FileMode.Create))
binWriter.Write(arrFile)
'binWriter.Flush() ' made no difference
binWriter.Close()
'ifrReport.Attributes.Remove("src") ' made no difference
ifrReport.Attributes.Add("src", "Uploads/123.jpg")
ifrReport.Visible = True
End Sub
End Class
Mark