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";
}
}