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] onclick event no working on some element in iPhone browser.

See original GitHub issue

Given the following code:

@page "/"
@inject IJSRuntime js

<div onclick="@BlazorClickEvent">I am a div, click me to say hello</div>

@functions{
    private void BlazorClickEvent()
    {
        js.InvokeAsync<object>("alert", "Hello from a div");
    }
}

If you run this on a browser like Chrome or Edge and click the div, the alert message will pop-up. If you run this on an iPhone browser and click the div the alert will not pop-up.

Below is a link you can use for testing, the link will open a Blazor project with a green square div you can use for experimentation.

https://iosbug.azurewebsites.net/

Not sure if this matter or not but the iPhone I am using to test is an iPhone 6s (this is the only Apple device I have for testing).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
campersaucommented, Jun 4, 2019

Have you tried this? Which is the workaround mentioned in https://github.com/aspnet/AspNetCore/issues/10725#issuecomment-498167475

@page "/counter"

@currentCount

<div style="cursor:pointer" onclick=@IncrementCount>Click me</div>

@functions {
    int currentCount = 0;

    void IncrementCount()
    {
        currentCount++;
    }
}
1reaction
rxelizondocommented, Jun 3, 2019

@SteveSandersonMS

  1. I don’t believe that the alert is the cause of the problem. In the repro above, I show a button with an onclick event attached to it where the click event fires an alert. The onclick event is fired correctly and the alert message is displayed without any problems (while on iOS).

  2. If I attach a JavaScrip onclick event to the div everything works fine, this tell me that under normal circumstances the click event works just fine.

That said, this looks like a Blazor issue, basically, whatever code you guys are generating behind the scenes to handle the click event is not agreeing with iOS.

Also, it is important to point out that the repro is extremely simplistic, it is just a barebones div with an onclick event attached to it (it can get any simpler that that). For such simplistic and common scenarios, it really doe not matter who the culprit is, this really needs to be handled by Blazor, if this was an oddball / corner case scenario then yes, a manual fix is justified but definite no in this case.

I will experiment later with this when time and resources permits (I don’t own an iPhone / iPad), however, like I said before, this overly simplistic scenario really needs to be handled by Blazor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor onclick event not triggered
I try to implement a simple onclick event handler like this sample https://blazorfiddle.com/s/counter but not working in my solution. The event ...
Read more >
[Solved]-Blazor onclick event not triggered-blazor
i tried to figure out most of the solutions for blazor inside the mvc app, some are incomplete so i've tried to prepare...
Read more >
Why does the onclick event not work, in my razor pages ...
Yes, I created an asp.net core hosted blazor webassembly application with a client, server and shared project. Instead of using a static html ......
Read more >
How is the onclick event of HTML element handled in Blazor?
Blazor provides support for event handling of HTML element by referring a pointer to the function that is used to handle the event,...
Read more >
ASP.NET Core Blazor event handling
An onclick event occurring in the child component is a common use case. To expose events across components, use an EventCallback.
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