October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Blazor Fundamentals: Make a Task Tracker Interactive

Connect Blazor task tracker controls to component state with data binding and event handlers, and learn why interactive render mode matters.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make a Blazor task tracker interactive, connect each control to component state: bind the title field, handle the form submission to add a task, and use event handlers to complete or remove tasks. Blazor then renders the list from that updated state. The example below keeps tasks in memory; it demonstrates the interaction loop, not storage across reloads. It follows Microsoft’s ASP.NET Core 10.0 todo-list tutorial, last updated November 11, 2025: Build a Blazor todo list app.

What makes a Blazor task tracker interactive?

A visible button or text box is not interactive merely because it appears in the page. The component needs a path from the browser action to .NET logic and back to rendered markup:

  1. The user types or clicks.
  2. A binding or event handler receives the change.
  3. Component state changes, such as the task title or task collection.
  4. Blazor renders the component using the current state.

For a small tracker, keep the task collection in the component and make the markup display that collection. An add handler that changes some other variable, without changing the displayed collection, will not add a row to the visible list.

Build a single-component task tracker

This illustrative Razor component holds tasks in memory. Its controls add a task, toggle completion, and remove a task. Put the component in a routable page or another component in your app. In a Blazor Web App, also ensure it is rendered interactively, as covered below.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@page "/tasks"

<h1>Task tracker</h1>

<form @onsubmit="AddTask" @onsubmit:preventDefault>
    <label for="task-title">Task title</label>
    <input id="task-title" @bind="newTitle" />
    <button type="submit">Add task</button>
</form>

@if (tasks.Count == 0)
{
    <p>No tasks yet. Add one above.</p>
}
else
{
    <ul>
        @foreach (var task in tasks)
        {
            <li @key="task.Id">
                <input type="checkbox"
                       checked="@task.IsComplete"
                       @onchange="() => ToggleTask(task)" />
                <span>@(task.IsComplete ? $"Completed: {task.Title}" : task.Title)</span>
                <button type="button" @onclick="() => RemoveTask(task)">Remove</button>
            </li>
        }
    </ul>
}

@code {
    private string newTitle = string.Empty;
    private readonly List<TaskItem> tasks = new();
    private int nextId = 1;

    private void AddTask()
    {
        var title = newTitle.Trim();
        if (title.Length == 0)
        {
            return;
        }

        tasks.Add(new TaskItem(nextId++, title));
        newTitle = string.Empty;
    }

    private void ToggleTask(TaskItem task)
    {
        task.IsComplete = !task.IsComplete;
    }

    private void RemoveTask(TaskItem task)
    {
        tasks.Remove(task);
    }

    private sealed class TaskItem(int id, string title)
    {
        public int Id { get; } = id;
        public string Title { get; } = title;
        public bool IsComplete { get; set; }
    }
}

How task entry works

@bind="newTitle" connects the input value to the component field. The form’s @onsubmit calls AddTask; @onsubmit:preventDefault prevents the browser’s normal form navigation so the Blazor handler can process the submission. The handler trims whitespace, ignores an empty title, appends a task to the collection used by the list, and clears the field.

HTML element binding uses the change event by default, which generally updates the bound value when the user commits the edit, often by leaving the field. If the component needs the value to update on every keystroke—for example, for immediate filtering—use @bind:event="oninput". Choose that timing when the behavior needs it rather than automatically: Microsoft’s Blazor data-binding guidance.

How completion and removal work

Each row is rendered from tasks. The checkbox’s @onchange and the remove button’s @onclick call handlers for that row’s task. Those handlers update the model or collection; the markup then reflects its current state. @key helps Blazor associate each rendered row with its task as the collection changes. For event-handler behavior and callback patterns, see Microsoft’s event-handling reference.

Make sure the page has an interactive render mode

In a Blazor Web App, static server-side rendering can produce the page’s HTML without enabling client-side UI events. Microsoft notes: “When using a Blazor Web App, most of the Blazor documentation example components require interactivity to function and demonstrate the concepts covered by the articles.” See the Razor components documentation and render modes reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an interactive render mode at the app or component level, according to the app’s design. Microsoft’s render-mode reference explains the available choices and how to apply them. If a button appears but does nothing, first check whether the page is only statically rendered. A component’s event attributes alone do not make a static page interactive.

Use validation when task entry needs more than a simple check

The example rejects a blank title in its handler, which is enough to illustrate the interaction loop but gives no field-level validation message. For structured validation, use a model with Blazor’s form components and validation support, such as EditForm with a validator and validation message. The Blazor forms overview describes the form and validation approach.

Validation of form input and persistence are separate concerns. This component does not save tasks to a database or retain them after the component is discarded or the page is reloaded. Add a storage service or other persistence layer if the app needs durable tasks; the UI example by itself makes no such guarantee.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep state flow clear as the tracker grows

A single component is a useful starting point because the input, handlers, and rendered list all use the same state. If rows or the entry form move into child components, pass values through parameters and report changes with callbacks such as EventCallback<T>. Avoid directly mutating a child component’s parameter: Microsoft’s data-binding guidance recommends binding and callback patterns so changes flow through the owning component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep handlers synchronous when their work is synchronous, as in this example. If a future handler awaits an API or storage operation, make it asynchronous and await that work rather than hiding it behind an untracked operation. The event-handling reference documents asynchronous handler patterns.

Troubleshoot a button or task list that does not respond

  • Nothing happens on click: Confirm the page or component has an interactive render mode, rather than static-only rendering.
  • The form navigates or refreshes: Handle its submit event with @onsubmit and prevent the browser’s default submission when appropriate.
  • The input value seems stale: Check whether default change-event timing is suitable, or whether the interaction needs @bind:event="oninput".
  • The list does not change: Verify the handler modifies the same collection or task model that the markup renders.
  • A child component’s value reverts or behaves unexpectedly: Use a parameter plus a change callback or the component binding pattern instead of mutating the parameter directly.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.