Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

878
Visualizações
Call multiple functions using @onclick in Blazor web pages

Two functions in blazor component should be called when I click on the button. Tried with comma, semicolon and parenthesis. Nothing works.

  <div class="col-md-auto"><button type="button" class="btn btn-light btn-sm" @onclick="@SearchTable"@*call two methods SearchTable and SortTable*@>Search</button></div>

The two functions are given below

@functions{
    public void SearchTable()
    {
        foreach (KeyValuePair<int, SearchCriteria> entry in SearchCritRefs)
        {
            entry.Value.setSearchCriteria(entry.Key);
        }
    }

    public void SortTable()
    {
        foreach (KeyValuePair<int, SortCriteria> entry in SortCritRefs)
        {
            entry.Value.setSortCriteria(entry.Key);
        }
    }

}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Do something like this:

<div class="col-md-auto"><button type="button" class="btn btn-light btn-sm"
    @onclick="@(() => { SearchTable(); SortTable(); })">Search</button></div>

<div>@message1</div>
<div>@message2</div>

@code{
    private string message1;
     private string message2;

   
    public void SearchTable()
    {
       message1 = "SearchTable";
    }

    public void SortTable()
    {
       message2 = "SortTable";
    }

}

Note: I've shown you how to call two methods when the click event is triggered as this is your question. If it is wise to code like that is something altogether different.

over 4 years ago · Santiago Trujillo Relatório

0

I would adopt the approach of calling a single function which can then call as many subsequent functions as required.

<button type="button" class="btn btn-light btn-sm" @onclick="@PerformSearch">Search</button>
@code{
    
    public void PerformSearch()
    {
        SearchTable();
        SortTable();
    }

    public void SearchTable()
    {
        foreach (KeyValuePair<int, SearchCriteria> entry in SearchCritRefs)
        {
            entry.Value.setSearchCriteria(entry.Key);
        }
    }

    public void SortTable()
    {
        foreach (KeyValuePair<int, SortCriteria> entry in SortCritRefs)
        {
            entry.Value.setSortCriteria(entry.Key);
        }
    }

}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda