首页 > 解决方案 > Blazor - HTML dropdown element once activated stops any further @OnClick event triggers

问题描述

Not sure if anyone has experienced this before but I have tried some solutions online but still can't manage to sort this. This is my situation:

I have create a simple app with a Dropdown Test button and a Normal Test button that once I click any on them I get the following outcome:

Normal Test

Once selected then the OnClick event triggers and just a simple console writeline stating the event was called gets actioned. This I can do over and over which is perfect.

Dropdown Test

Once selected then the OnClick event triggers and just a simple console writeline stating the event was called gets actioned. This I can only do once, thereafter it fails to call the OnClick event again which I need it to do.

Code:

<div class="container">
  <button class="btn btn-primary" @onclick="OnTest" type="button">Normal Test</button>
  <br />
  <div class="dropdown">
   <button class="btn btn-primary dropdown-toggle" @onclick="OnTest" type="button" data-toggle="dropdown">
     Dropdown Test
   </button>
   <ul class="dropdown-menu">
     <li><a href="#">ValueA</a></li>
     <li><a href="#">ValueB</a></li>
     <li><a href="#">ValueC</a></li>
   </ul>
  </div>
</div>

@code
{
private void OnTest()
    {
        Console.WriteLine("PauseFeed called!");
    }
}

I need the dropdown button to run the OnClick event everytime I select the dropdown, not sure if there is a statechange event to run or how I would do this.

Any feedback would be appreciated.

Thanks...

标签: c#htmlblazorblazor-server-side

解决方案


感谢收到的反馈。

我查看了提供的选项,并决定只更改设计。

谢谢。


推荐阅读