首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上载文件丢失

问上载文件丢失
EN

Stack Overflow用户
提问于 2016-02-03 07:17:27
回答 1查看 1.4K关注 0票数 1

我需要上传一个文件。当文件上传时,我需要显示进度条。但是,当我单击updatepanel中的“上传”按钮时,fileupload中的文件在我添加触发器时消失,该文件将上载,但是进度条将不会显示在这里我的代码。

​

代码语言:javascript
复制
<%@ Page Title="" Language="C#" MasterPageFile="~/site.Master" AutoEventWireup="true" CodeBehind="upload.aspx.cs" Inherits="fix_asset.upload" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .auto-style2 {
            height: 23px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table style="margin:auto; padding-top:50px">
                <tr>
                    <td style="font-weight: 600; font-size: large; background-color: #0000FF; border: thin solid #000000">
                        UPLOAD MASTER FILE
                    </td>
                </tr>
                <tr style="border: thin solid #000000; background-color: #DBD5FD;">
                    <td>
                        <table>
                            <tr>
                                <td style="width:100px">
                                    Location
                                </td>
                                <td>
                                    <asp:FileUpload ID="FileUpload1" runat="server" />
                                </td>
                                <td style="width:100px">
                                    <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" OnClientClick="uploadfile()" style="width:100px" />
                                </td>
                                <td style="width:100px">
                                    <asp:Button ID="Button2" runat="server" Text="Sampling" OnClick="Button2_Click" style="width:100px" />
                                </td>

                            </tr>
                            <tr>
                                <td colspan="4" style="text-align:center" class="auto-style2">
                                    <asp:Label ID="lblNotification" runat="server" Text=""></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </td>
                    </tr>
            </table>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:Button ID="Button4" runat="server" Text="Button" style="visibility:hidden" OnClick="Button4_Click" />
            <asp:HiddenField ID="HiddenField2" runat="server" />
            <br />
            <hr />
            <br />

        </ContentTemplate>
    </asp:UpdatePanel>
                <table style="margin:auto; padding-top:50px; width:560px; border-collapse: collapse;">
                <tr style="font-weight: 600; font-size: large; background-color: #0000FF; border: thin solid #000000">
                    <td colspan="3" >VLOOK UPLOAD</td>
                </tr>
                <tr style="border: thin solid #000000; background-color: #DBD5FD; padding:5px 5px 5px 5px">
                    <td>
                        Location
                    </td>
                    <td>
                        <asp:FileUpload ID="FileUpload2" runat="server" style="width:100%" />
                    </td>
                    <td>
                        <asp:Button ID="Button3" runat="server" style="width:100%" Text="Upload" onclick="Button3_Click" OnClientClick="uploadfile2()" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:Label ID="lblNotification2" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                
            </table>
    <script>
        function uploadfile() {
            document.getElementById('<%= HiddenField1.ClientID%>').value = document.getElementById('<%= FileUpload1.ClientID%>').value;
        }
        function uploadfile2() {
            document.getElementById('<%= HiddenField2.ClientID%>').value = document.getElementById('<%= FileUpload2.ClientID%>').value;
        }
    </script>
</asp:Content>

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-03 08:21:36

AJAX更新面板用于防止页面完全回发。使用update面板,我们可以部分回发页面。部分页面回发执行以下操作

1.提高应用程序的性能

2.减少应用程序的页面加载时间。

3.减少应用程序与服务器之间的往返时间。

4.只有网页中需要刷新的部分才能得到回发。

我们知道我们可以使用文件上传控件将文件上传到服务器。但是,如果在update面板中使用文件上传控件,那么它就不能工作。原因是文件上传控件不适用于异步回发。

将此添加到窗体标记中,然后添加触发器,如下所示

代码语言:javascript
复制
<form id="form1" runat="server" method="post" enctype="multipart/form-data" >
.....
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID = "uploadbuttonID"/>     
</Triggers>
</asp:UpdatePanel>
.....
</form>

参考这个链接..。

http://www.aspsnippets.com/Articles/Display-Show-ASPNet-AJAX-UpdateProgress-with-UpdatePanel-PostBackTrigger.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35170742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档