如何在Tabbed界面控件中上传asp.net中的文件

时间:2011-06-28 10:01:12

标签: c# asp.net tabbed-interface

我有一个asp.net(c#)Web应用程序,我正在使用Tabbed界面来显示表单。在Tabbed界面中有4个选项卡在第4个选项卡中我有文件上传控件,当我尝试上传时文件它不带文件它总是显示空值。如何在Tabbed界面上传文件请帮助我。

<cc1:TabPanel runat="server" HeaderText="Documents" ID="TabPanel4">
    <triggers>
        <asp:PostBackTrigger ControlID="SyncButton" />
    </triggers>
    <ContentTemplate>
        <asp:Button ID="SyncButton" runat="server" Text="Test" />
        <table>
            <tr>
                <td>Documnets</td>
            </tr>
            <tr>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                    <br />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnfupload" runat="server" 
                        CausesValidation="false" Text="Upload File"
                        OnClick="btnfupload_Click" />
                </td>
                <td>
                    <asp:Label ID="lblstatus" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</cc1:TabPanel>

代码背后:

           protected void btnfupload_Click(object sender, EventArgs e)
    {

            try
            {
                if (FileUpload1.HasFile)
                {
                    if (!Directory.Exists(Server.MapPath("Documents")))
                    {
                        Directory.CreateDirectory(MapPath("Documents"));

                    }
                    string docment = FileUpload1.PostedFile.FileName;
                    string path = System.IO.Path.GetFileName(docment);
                    FileUpload1.PostedFile.SaveAs(Server.MapPath("Documents/") + path);

                }
            }
            catch
            {

            }
        }
    }

1 个答案:

答案 0 :(得分:1)

使用AsyncFileUpload