I have this asp code:
<asp:Panel runat="server">
<div class="row2">
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" id="fileSelect" name="fileSelect" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="load" OnClick="btnUpload_Click2" CausesValidation="False" />
</div>
</asp:Panel>
Here the generated HTML code on the browser:
<div class="row2">
<input name="ctl00$ContentPlace$fileSelect" type="file" id="ctl00_ContentPlace_fileSelect" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<input type="submit" name="ctl00$ContentPlace$btnUpload" value="load" id="ctl00_ContentPlace_btnUpload">
</div>
</div>
Here the code behind:
protected void btnUpload_Click2(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["fileSelect"];
}
After I select a file with help of input file element the btnUpload is pressed the code behind fired but I always get file value null.
If I change this row:
HttpPostedFile file = Request.Files["fileSelect"];
To this row:
HttpPostedFile file = Request.Files["ctl00$ContentPlace$fileSelect"];
I get the selected file in file variable on the server.
So my question is why I can't get file if I use this row:
HttpPostedFile file = Request.Files["fileSelect"];