Click here to Skip to main content
14,145,240 members

Asp.net fileupload prevents onclick event?

Martin Wieland asked:

Open original thread
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";
    }
}
Tags: ASP.NET, WebForms, event

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190518.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100