Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

873
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!