简体   繁体   English

在c#asp.net中上传图片时FileUpload没有文件

[英]FileUpload has no file when uploading image in c# asp.net

FileUpload shows null file when uploading image in ASP.NET C#. 在ASP.NET C#中上传图像时,FileUpload显示空文件。 My page is connected with a master page so when i click on upload button FileUpload control shows null file but when i use it without master page file upload successfully, please tell me how to short out this problem. 我的页面与母版页连接,因此当我单击上载按钮FileUpload控件时显示空文件,但是当我在没有母版页上载成功的情况下使用它时,请告诉我如何缩短此问题。 I am using this code. 我正在使用此代码。

<table>
        <tr>
    <td>Enrollment Id</td>
    <td>:</td>
    <td>
        <asp:TextBox ID="txtEnrollmentNo" runat="server" CssClass="text" AutoPostBack="true" OnTextChanged="txtEnrollmentNo_TextChanged"></asp:TextBox>
    </td>
    <td></td>
    </tr>
    <tr>
    <td colspan="4" style="font-weight:bold; text-align:center;">
    Student Details
    </td>
    </tr>
    <tr>
    <td colspan="3" style="background-color:#eee; padding:5px;">
    Upload Photo
    </td>
    </tr>
    <tr>
    <td colspan="3">
        <asp:Image ID="imgPhoto" runat="server" CssClass="imageUpload" />
    </td>
    <td></td>
    </tr>

    <tr>
    <td colspan="3">
        <asp:FileUpload ID="fileUploadPhoto" runat="server" onchange="readPhotoURL(this)" />

         </td>
    <td></td>
    </tr>
    </table>
    <div class="commonArea">
        <asp:Button ID="btnSubmit" runat="server" Text="Upload & Save" TabIndex="3"  onclick="btnSubmit_Click" />
    </div>

Code behind using 使用后的代码

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string extension = Path.GetExtension(fileUploadPhoto.PostedFile.FileName);
            fileUploadPhoto.PostedFile.SaveAs(Server.MapPath("~/StudentImages/Photo/") + txtEnrollmentNo.Text + extension);
            MessageBox("success", txtEnrollmentNo.Text); 

        }
        catch (Exception ex)
        {
            MessageBox("error",ex.Message);
        }
    }

请检查您的母版页是否不包含更新面板,并且不使用asp .net ajax,因为这是此问题的最常见原因。

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

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