【スクリプト】iframeにページをロードするタイミングでファイルのダウンロードを行い、SPREADのセルをクリックするとエラーが発生する
対象製品
SPREAD for ASP.NET 7.0J
詳細
iframeタグ内に他のページをロードするタイミングでファイルのダウンロードを行うと、その後にSPREADをクリックするとエラーが発生します。
【再現手順】
1.新規のWebフォーム"PdfReportView.aspx"と"WebFrom1.aspx"を作成し、
"WebFrom1.aspx"にはSpreadと標準コントロールのButton、およびサンプルのようにiframeタグを配置します。
2.それぞれのWebフォームに下記のサンプルコードをコピーし、
"WebFrom1.aspx"でアプリケーションを実行します。
3.Webページの起動後、Buttonを押下してPDFの保存を行います。
4.保存処理の完了後、Spread上にある任意のセルをクリック。
--- スクリプトエラー
--- 「Microsoft JScript 実行時エラー: プロパティ '__justFiltered'の値を取得できません: オブジェクトは Nullまたは未定義です。」
--- が発生します。
※ 上記の操作を行ってもエラーが発生せず、引き続き操作が可能な状態になるのが正常動作です。
【再現コード】
---------------------------------
WebFrom1.aspx.vb Webフォームクラス
---------------------------------
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strScript As New StringBuilder
strScript.AppendFormat("<script type='text/javascript'>PdfDownload('PdfReportView.aspx?PdfFileName={0}');<" + "/script>", "PDF/test.pdf")
ClientScript.RegisterStartupScript(Me.GetType, "test", strScript.ToString())
End Sub
---------------------------------
スクリプト
---------------------------------
function PdfDownload(sUrl) {
document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
}
---------------------------------
WebFrom1.aspx コード
---------------------------------
<asp:Button ID="Button1" runat="server" Text="test" Width="70px" />
<br />
<br />
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
<commandbar backcolor="Control" buttonfacecolor="Control" buttonhighlightcolor="ControlLightLight" buttonshadowcolor="ControlDark">
</commandbar>
<sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</sheets>
</FarPoint:FpSpread>
<iframe id="DownloadFrame" style="visibility:hidden"></iframe>
---------------------------------
PdfReportView.aspx.vb Webフォームクラス
---------------------------------
Public Class PdfReportView
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim pdfPath As String
Dim l As Integer
Dim strName As String
pdfPath = Request("PdfFileName")
l = pdfPath.LastIndexOf("¥")
strName = pdfPath.Substring(l + 1)
strName = HttpUtility.UrlEncode(strName)
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename =" & strName)
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("Shift-Jis")
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.WriteFile(pdfPath) 'サーバーサイドのファイル名
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.Close()
'HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
Return
End Try
End Sub
End Class
【再現手順】
1.新規のWebフォーム"PdfReportView.aspx"と"WebFrom1.aspx"を作成し、
"WebFrom1.aspx"にはSpreadと標準コントロールのButton、およびサンプルのようにiframeタグを配置します。
2.それぞれのWebフォームに下記のサンプルコードをコピーし、
"WebFrom1.aspx"でアプリケーションを実行します。
3.Webページの起動後、Buttonを押下してPDFの保存を行います。
4.保存処理の完了後、Spread上にある任意のセルをクリック。
--- スクリプトエラー
--- 「Microsoft JScript 実行時エラー: プロパティ '__justFiltered'の値を取得できません: オブジェクトは Nullまたは未定義です。」
--- が発生します。
※ 上記の操作を行ってもエラーが発生せず、引き続き操作が可能な状態になるのが正常動作です。
【再現コード】
---------------------------------
WebFrom1.aspx.vb Webフォームクラス
---------------------------------
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strScript As New StringBuilder
strScript.AppendFormat("<script type='text/javascript'>PdfDownload('PdfReportView.aspx?PdfFileName={0}');<" + "/script>", "PDF/test.pdf")
ClientScript.RegisterStartupScript(Me.GetType, "test", strScript.ToString())
End Sub
---------------------------------
スクリプト
---------------------------------
function PdfDownload(sUrl) {
document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
}
---------------------------------
WebFrom1.aspx コード
---------------------------------
<asp:Button ID="Button1" runat="server" Text="test" Width="70px" />
<br />
<br />
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
<commandbar backcolor="Control" buttonfacecolor="Control" buttonhighlightcolor="ControlLightLight" buttonshadowcolor="ControlDark">
</commandbar>
<sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</sheets>
</FarPoint:FpSpread>
<iframe id="DownloadFrame" style="visibility:hidden"></iframe>
---------------------------------
PdfReportView.aspx.vb Webフォームクラス
---------------------------------
Public Class PdfReportView
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim pdfPath As String
Dim l As Integer
Dim strName As String
pdfPath = Request("PdfFileName")
l = pdfPath.LastIndexOf("¥")
strName = pdfPath.Substring(l + 1)
strName = HttpUtility.UrlEncode(strName)
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename =" & strName)
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("Shift-Jis")
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.WriteFile(pdfPath) 'サーバーサイドのファイル名
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.Close()
'HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
Return
End Try
End Sub
End Class
回避方法
製品に必要なスクリプトダウンロード前にPDFファイルのダウンロードが実行されることによって発生する不具合の為、WebForm1.aspx のクライアントスクリプト関数 PdfDownload にて、その内容を下記のようにしてPDFのダウンロードタイミング遅延させることで、回避します。
【回避コード】
function PdfDownload(sUrl) {
//document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
setTimeout(function () {
document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
}, 500);
}
【回避コード】
function PdfDownload(sUrl) {
//document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
setTimeout(function () {
document.getElementById('DownloadFrame').contentWindow.location.href = sUrl;
}, 500);
}