question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor file input click not working in firefox

See original GitHub issue

Describe the bug

Trigger a click event via Javascript on an input element of type file is not working. When searching the web for my problem i found this stackoverflow thread. I already opened an issue here #20228 but it was closed with the reason: “Firefox security issue” which is not right.

To Reproduce

Create an hidden input file element in a razor component. Then create a button. On the button click call a void, inside the void method call the IJsRuntime invoke method to trigger your js function that clicks the input file element by id.

It’s not a firefox security feature. Plain html is working. See here: https://jsfiddle.net/chxnbmqt/

There are many other way’s to achieve custom styling of a file input element (already implemented another way). Still i think this may be a bug related to blazor.

Further technical details

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version

IDE: VS

<TargetFramework>netcoreapp3.1</TargetFramework>

dotnet --info: .NET Core SDK: Version: 3.1.101 Commit: b377529961

Laufzeitumgebung: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support): Version: 3.1.2 Commit: 916b5cba26

.NET Core SDKs installed: 2.2.207 [C:\Program Files\dotnet\sdk] 3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fabianschurzcommented, May 8, 2020

@captainsafia Thanks for your deep investigation on this.

The workaround is to use plain HTML and JS.

<input type="file" id="fileInput" style="display: none;" onchange="YourAfterFileSelectedMethod"/> 
<button onclick="ClickFileInput()">Import</button>

function ClickFileInput() {
    document.getElementById('fileInput').click();
}
0reactions
mkArtakMSFTcommented, Oct 19, 2022

Hi. Thanks for contacting us. We’re closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor file input click not working in firefox
I am creating a blazor application in which I am using the hidden file input and click() method to open the file picker....
Read more >
Blazor file input click not working in firefox · Issue #20228
Create an input file element in a razor component. Then create a button on the component. On the button click call a void,...
Read more >
1610726 - File input click not working for blazor application
I am creating a blazor application in which I am using the hidden file input and click() method to open the file picker....
Read more >
[Solved]-Blazor file input click not working in firefox-blazor
I have the same problem. Seems to be a JsInterop related bug. Created an issue in aspnetcore repo: https://github.com/dotnet/aspnetcore/issues/20228.
Read more >
[Solved] File upload not working in mozila firefox.
When you nest the control inside a <button> , that button receives the click, and does not pass it on to the invisible...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found