简体   繁体   English

ASP.NET iframe有时不会更新

[英]ASP.NET iframe doesn't update, sometimes

Below is my simplified .aspx file. 下面是我的简化的.aspx文件。 Sometimes after clicking the 'update preview' button the iframe containing a modified .pdf file shows the up to date file. 有时,点击“更新预览”按钮后,包含修改过的.pdf文件的iframe会显示最新文件。 Sometimes, though, it takes several clicks until the iframe shows the up to date file. 不过,有时,它需要多次单击,直到iframe显示最新文件。

Even if I redirect to the file directly in a new window, the .pdf file is still not up to date! 即使我直接在新窗口中重定向到该文件,.pdf文件仍然不是最新的! (On my server's disk it is, though) (尽管在我服务器的磁盘上)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="pdfwebform.WebForm1" %>

<script runat="server">
void download_Click(object sender, EventArgs e)
{
    Response.Redirect("http://dev-db-02/pdf/catalog.pdf");
}

void Button1_Click(object sender, EventArgs e)
{
    string answer = call_pdf(make_new, retails_array, restypes_array, selected_kids, brands_array);
    if (answer != "failed")
    {
        label1.Text = "Done!";
    }
    else
    {
        label1.Text = "No models meet selected criteria.";
    }
}

</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Generate PDF Catalog</title>
        <link href="theme.css" rel="stylesheet" type="text/css" />
        <!--
        <style type="text/css">
            .auto-style1 {
                width: 100%;
                height: 105px;
            }
            .auto-style2 {
                width: 557px;
            }
        </style>
        -->
        <style type="text/css">
            .auto-style1 {
                width: 84%;
            }
            .auto-style2 {
                text-align: left;
                width: 87px;
            }
            .auto-style3 {
                text-align: left;
                width: 486px;
            }
        </style>
    </head>
    <body>
        <script type="text/javascript">
        function appear() {
            document.getElementById("preview").style.display = 'block';
        }
        </script>

        <script type="text/javascript">
        function updatepreview() {
            if (document.getElementById("label1").innerHTML != "") {
                var iframe = document.getElementById("preview1");
                iframe.src = iframe.src;
                iframe.src = iframe.src;
                iframe.src = iframe.src;
            }
            else{
                document.getElementById("label1").innerHTML = "Please Wait...";
            }
        }
        </script>

        <script type="text/javascript">
            function update_iframe() {
                var iframe = document.getElementById("preview1");
                iframe.src = iframe.src;
                iframe.src = iframe.src;
                iframe.src = iframe.src;
            }
        </script>

        <script type="text/javascript">
        function dot() {
            if (document.getElementById("label1").innerHTML == "d") {
                document.getElementById("label1").innerHTML = "nope";
            }
            else {
                document.getElementById("label1").innerHTML = "d";
            }
        }
        </script>

        <h1>Generate PDF Catalog</h1>
        <form id="form1" runat="server">
            <!-- <embed id="preview" src="http://dev-db-02/pdf/catalog.pdf" width="500px" height="500px" runat="server" /> -->
            <iframe id="preview1" src="http://dev-db-02/pdf/catalog.pdf" width="500" height="500" runat="server"></iframe>
                <!-- Add to File Feature
                <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                    <asp:ListItem Selected="True" Value="new">Create New PDF</asp:ListItem>
                    <asp:ListItem Value="old">Add to Existing PDF</asp:ListItem>
                </asp:RadioButtonList>
                -->
                <table class="auto-style1">
                    <tr>
                        <td class="auto-style2">
                            <b>Retail:<br />
                            </b>
                <asp:ListBox ID="ListBox5" runat="server" Height="45px" SelectionMode="multiple" Width="230px">
                    <asp:ListItem Selected="True" Value="Yes">Yes</asp:ListItem>
                    <asp:ListItem Value="No">No</asp:ListItem>
                </asp:ListBox>
                <b>
                            <br />
                            <br />
                            Res Type:</b><br />
                <asp:ListBox ID="ListBox4" runat="server" SelectionMode="Multiple" Height="69px" Width="230px">
                    <asp:ListItem Selected="True" Value="OPTICAL">OPTICAL</asp:ListItem>
                    <asp:ListItem Value="KIDS">KIDS</asp:ListItem>
                    <asp:ListItem Value="SUN">SUN</asp:ListItem>
                </asp:ListBox>
                            <br />
                            <br />
                            <b>Brand:</b><br />
                <asp:ListBox ID="ListBox3" runat="server" Height="142px" Width="230px" SelectionMode="multiple" >
                    <asp:ListItem Selected="True" Value="'AS'">ASPIRE</asp:ListItem>
                    <asp:ListItem Value="'BCBG'">BCBGMAXAZRIA</asp:ListItem>
                    <asp:ListItem Value="'CVO'">CLEARVISION</asp:ListItem>
                    <asp:ListItem Value="'CH'">COLE HAAN</asp:ListItem>
                    <asp:ListItem Value="'DD'">DILLI DALLI</asp:ListItem>
                    <asp:ListItem Value="'DH'">DURAHINGE</asp:ListItem>
                    <asp:ListItem Value="'ET'">ELLEN TRACY</asp:ListItem>
                    <asp:ListItem Value="'IZOD'">IZOD</asp:ListItem>
                    <asp:ListItem Value="'IZX'">IZOD PERFORMX</asp:ListItem>
                    <asp:ListItem Value="'JMC'">JESSICA MCCLINTOCK</asp:ListItem>
                    <asp:ListItem Value="'JC'">JUNCTION CITY</asp:ListItem>
                    <asp:ListItem Value="'ME'">MARC ECKO</asp:ListItem>
                    <asp:ListItem Value="'OP'">OCEAN PACIFIC</asp:ListItem>
                    <asp:ListItem Value="'PT'">PURITI</asp:ListItem>
                </asp:ListBox>
                            <br />
                            <br />
                            <br />



                        </td>
                        <td colspan="3">
            <asp:Label id="label1" runat="server" Font-Bold="true" onchange="updatepreview()"></asp:Label>
                            <br />
            <!-- <embed id="preview" src="http://dev-db-02/pdf/catalog.pdf" width="500px" height="500px" runat="server" /> -->
            <iframe id="preview1" src="http://dev-db-02/pdf/catalog.pdf" width="500" height="500" runat="server"></iframe>
                            <br />

            <!-- <iframe id="frame" style="display:none"></iframe> -->
            <!-- <a href="javascript:download('http://dev-db-02/pdf/catalog.pdf')">download</a> -->

                    &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="auto-style2">

                <asp:Button id="Button1" runat="server" Font-Bold="True"
                Font-Names="Verdana" Font-Size="12" OnClick="Button1_Click" OnClientClick="updatepreview()"
                Text="Submit"></asp:Button>


                        </td>
                        <td class="auto-style3">

                            *<font size="3">Hold Control/Command 
                            <br />
&nbsp;+ Click to select multiple</font>

                        </td>
                        <td class="auto-style3">
                            <font size="3">
                <asp:Button ID="Button2" runat="server" Text="Update Preview" OnClientClick="update_iframe()" />

                            </font>

                        </td>
                        <td class="align-right">
                            &nbsp;</td>
                    </tr>
                </table>

                <br />
                <br />
            </div>
        </form>
        <script type="text/javascript">
            function download() {
                window.open("http://dev-db-02/pdf/catalog.pdf");
            }
        </script>
    </body>
</html>
 void download_Click(object sender, EventArgs e)
{
    Response.ContentType = "Application/pdf";
    Response.AppendHeader("Content-Disposition", "attachment; filename=help.pdf");
    Response.TransmitFile(Server.MapPath("~/pdf/catalog.pdf"));
    Response.End();
}

in your case you are redirecting the response with 301 to url witch return your file, the problem is that you are using 301 redirect and even if you are changing disk file browser will return cached 301 redirect (same file) 在您的情况下,您正在使用301将响应重定向到url女巫返回您的文件,问题是您使用的是301重定向,即使您更改磁盘文件浏览器也将返回缓存的301重定向(相同的文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM