Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I stumbled upon an issue that seems to be rather simple... yet I can't seem to get it work. I'm working on a asp.net C# webforms application and we have the need to upload a file. I have put a fileupload control on the page and a button. The idea is that the user selects a file and then clicks on the button to do the actual upload. Plenty of examples available, and I tried several - to no avail.

The problem is that after the user selects a file and then clicks the button, the onclick event of that button is never fired. The fileupload reverts to "No file chosen" and nothing has happened. The odd thing is, that when the file upload is in the state where it shows "No file chosen" the onclick is fired... beats me.

I'm using bootstrap, jquery, a scriptmanager and masterpages so I made a simple form that is stripped down to plain html and it's still not working. I have put a breakpoint in the onclick event of the button. If there is no file selected this breakpoint is hit, but if I do select a file and then hit the button it is not hit and nothing happens.

I have included the markup and codebehind. Has anyone experienced this behavior? Any help is appreciated, thanks in advance!

What I have tried:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testupload.aspx.cs" Inherits="Admin_testupload" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server"></asp:FileUpload>
            <hr />
            <asp:LinkButton ID="lbt_Go" runat="server" OnClick="lbt_Go_Click">Test</asp:LinkButton>
        </div>
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_testupload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void lbt_Go_Click(object sender, EventArgs e)
    {
        var x = "breakpoint";
    }
}
Posted
Updated 2-Nov-18 21:09pm
v3

Try to use update panel. which help you resolve your problem.

<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        <asp:FileUpload ID="FileUpload1" runat="server"></asp:FileUpload>
        <hr />
        <asp:LinkButton ID="lbt_Go" runat="server" OnClick="lbt_Go_Click">Test</asp:LinkButton>        
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID = "lbt_Go" />
    </Triggers>
</asp:UpdatePanel>
 
Share this answer
 
v2
Comments
F-ES Sitecore 2-Nov-18 8:12am    
I don't think FileUpload works inside an UpdatePanel. It doesn't work asynchronously anyway.
Thank you for your suggestion, but using an update panel did not help.

The Ajax Control Toolkit has an advanced file upload that did work so I was already preparing to go that route when I finally found the answer: the standard fileupload control is by default limited to ~ 4MB and all my testfiles happened to be larger. Once I changed this limit in web.config things worked as expected. It would have been nice to get an exception of some sort to trigger this issue though.

I consider myself a silver fox webforms designer but I have never needed to upload files before. I do feel a bit foolish that I ran into this issue, but I'm glad it's working now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900