Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Is there a blazor way of simulating a click event on an html element?

$
0
0

I have two elements, an InputFile and a button. And I want to simulate a click on InputFile upon clicking the button. I have it working with Js now but would like to know if there's a blazor way of doing it.An example gif

and this is the current blazor code

<InputFile id="filePicker" /><button type="button" @onclick="OpenFilePicker">or Select</button>private async Task OpenFilePicker() => await JsRuntime.InvokeVoidAsync("clickElement");

and with this Js code I can make it work though,

clickElement = () => document.getElementById('filePicker').click();

Is there a better solution without Js dependency ?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>