FileUpload Control HasFile is always False
<p>I have a FileUpload Control in my Asp.Net Webforms Project that doesn't wasn't to run the <code>if(fuPostPhotoCreate.HasFile) { }</code> block.</p>

<p>Here's the relevant aspx page code:</p>

<pre><code>&lt;asp:UpdatePanel ID="upMain" runat="server"&gt;
    &lt;ContentTemplate&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="txbPostPhotoCreate"&gt;Picture&lt;/label&gt;
          &lt;asp:FileUpload ID="fuPostPhotoCreate" runat="server" ToolTip="Upload Picture" /&gt;
          &lt;asp:RegularExpressionValidator ID="revPostPhotoCreate" runat="server" ControlToValidate="fuPostPhotoCreate" ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.png|.jpg|.jpeg|.gif)$" CssClass="text-danger" ErrorMessage='Please select a valid image format (".png", ".jpg", ".jpeg" or ".gif")' Display="Dynamic" /&gt;
        &lt;/div&gt;
        &lt;asp:LinkButton ID="btnCreatePost" runat="server" CssClass="btn btn-success" OnClick="btnCreatePost_Click" CausesValidation="true" ToolTip="Create Post" &gt;
            &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;
            Create Post
        &lt;/asp:LinkButton&gt;
    &lt;/ContentTemplate&gt;
    &lt;Triggers&gt;
        &lt;asp:PostBackTrigger ControlID="btnCreatePost" /&gt;
    &lt;/Triggers&gt;
&lt;/asp:UpdatePanel&gt;
</code></pre>

<p>Then I have the following in the aspx.cs page:</p>

<pre><code>protected void btnCreatePost_Click(object sender, EventArgs e)
{
    // (1) Some non relevant code
    if (fuPostPhotoCreate.HasFile)
    {
        // (2) More non relevant code
    }
    // (3) Final non relevant code
}
</code></pre>

<p>My problem is that the <code>fuPostPhotoCreate.HasFile</code> always returns <code>false</code> even when I have uploaded a file and it's in the the <code>fuPostPhotoCreate</code> control.  Therefor the non relevant code (2) never gets run (when it should get run when the <code>fuPostPhotoCreate</code> contains a file.</p>

<p>What could I be doing wrong?  The non relevant code (1) and (3) does run successfully.</p>

<p><strong>EDIT:</strong></p>

<p>Here is the full code of that button click:</p>

<pre><code>if (!Page.IsValid)
    return;

try
{
    var post = new Models.EF.Post();

    post.DateCreated = DateTime.Now;
    post.Title = txbPostTitleCreate.Text;
    post.Body = txbPostBodyCreate.Text;
    post.IsPublic = cbxPostPublicCreate.Checked;

    int postId = efService.CreatePost(post);
    gvDisplayPosts.DataBind();

    if (fuPostPhotoCreate.HasFile)
    {
        //? Get filename extension
        string fileName = Path.GetFileName(fuPostPhotoCreate.FileName);
        string extension = fileName.Substring(fileName.LastIndexOf('.'));

        //? Specify the path to save the uploaded file to.
        string tempPath = Server.MapPath("~/Uploads/Temp") + "\\" + postId.ToString() + extension;
        string savePath = Server.MapPath("~/Uploads/Posts") + "\\" + postId.ToString() + extension;
        string saveThumbnailPath = Server.MapPath("~/Uploads/Posts/Thumbnails") + "\\" + postId.ToString() + extension;

        #region Remove EXIF Data
        var image = System.Drawing.Image.FromFile(tempPath);

        if (Array.IndexOf(image.PropertyIdList, 274) &gt; -1)
        {
            var orientation = (int)image.GetPropertyItem(274).Value[0];
            switch (orientation)
            {
                case 1:
                    // No rotation required
                    break;
                case 2:
                    image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    break;
                case 3:
                    image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;
                case 4:
                    image.RotateFlip(RotateFlipType.Rotate180FlipX);
                    break;
                case 5:
                    image.RotateFlip(RotateFlipType.Rotate90FlipX);
                    break;
                case 6:
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;
                case 7:
                    image.RotateFlip(RotateFlipType.Rotate270FlipX);
                    break;
                case 8:
                    image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;
            }   
            //This EXIF data is now invalid and should be removed.
            image.RemovePropertyItem(274);
        }   

        image.Save(savePath);
        image.Dispose();

        var tempDir = new DirectoryInfo(Server.MapPath("~/Uploads/Temp"));
        foreach (FileInfo file in tempDir.GetFiles())
        {
            file.Delete();
        }
        #endregion

        //? Convert savePath photo to thumnail and save to saveThumbnailPath
        var fullImage = System.Drawing.Image.FromFile(savePath);
        var thumbnailImage = new ImageResizer.ImageJob(fullImage, saveThumbnailPath, new ImageResizer.Instructions("width=150;mode=stretch;autorotate=false"));
        thumbnailImage.Build();

        string dbPathName = "~/Uploads/Posts/" + postId.ToString() + extension;
        string dbThumbnailPath = "~/Uploads/Posts/Thumbnails/" + postId.ToString() + extension;
        efService.SetPostPath(postId, dbPathName);
        efService.SetPostThumbnailPath(postId, dbThumbnailPath);
    }

    //? Clear Fields
    txbPostTitleCreate.Text = string.Empty;
    txbPostBodyCreate.Text = string.Empty;
    cbxPostPublicCreate.Checked = false;

    //? Hide pnlAddPost
    pnlAddPost.Visible = false;
}

catch (Exception ex)
{
    string errorMessage = ex.Message.ToString();
    lblExceptionMessage.Text = errorMessage;

    lblExceptionMessage.Visible = true;
}
</code></pre>

<p><strong>Note:</strong>
I have found that it seems to work if I change the file to be uploaded at least once before submitting.</p>