How to set page title in blazor?

From ASP.NET CORE 6.0, the official docs says that we can Influence HTML <title> tag elements easily by using PageTitle component. Add the HeadOutlet Component in Program.cs builder.RootComponents.Add<HeadOutlet>(“head::after”); Then use PageTitle Component <PageTitle>@title</PageTitle> Update 1: Looks like this API has been put on hold to improve further. This has been removed from official docs link. … Read more

How to set the focus to an InputText element?

In .NET5 it will be much simpler: <button @onclick=”() => textInput.FocusAsync()”>Set focus</button> <input @ref=”textInput”/> @code { ElementReference textInput; } NOTE: this feature was introduced in .NET5 Preview 8 so might change until the final release! Also worth mentioning that in .NET5 RC1 JavaScript isolation was introduced via JS Module export/import. So if you still need … Read more

Disable layout for page under Blazor

In my Blazor-server-side project, i resolved this issue with following two steps. Step 1: First create a new empty razor component named EmptyLayout. EmptyLayout.razor @inherits LayoutComponentBase <div class=”main”> <div class=”content px-4″> @Body </div> </div> Step 2, To set Layout=null, I use the below code in the top of all required pages @layout EmptyLayout

Require authorization on ALL Blazor pages

I believe that will work… Place the following code snippet in the _Imports.razor file @using Microsoft.AspNetCore.Authorization @attribute [Authorize] In that case, when the Index page is hit, the user will be redirected to the Login page. If you want to perform authentication before the Blazor App is being render, add the code snippet from above … Read more

how to call child component method from parent component in blazor?

First you need to capture a reference of your child component: <ChildComponent @ref=”child” /> Then you can use this reference to call the child’s component methods as you do in your code. <button onClick=”@ShowModal”>show modal</button> @code{ ChildComponent child; void ShowModal(){ child.Show(); } } The namespace of your component need to be added by a using … Read more