How can I load a dialog on demand?

To load a dialog on demand in Blazor, we can create a modal dialog with a conditional attribute (@if). We can load the dialog in the HTML page by using the conditional attribute, which will render based on the Boolean property.In the following code, we render the dialog on a button-click event in which the ShowPopup property will be set as true and the dialog will be shown on the page. We can remove the dialog by setting the ShowPopup property as false.

Does Blazor support end-to-end testing?

Yes, Blazor supports E2E testing with the help of the Steve’s prototype library. This library can be included in your testing projects for E2E testing. Its compatible with traditional unit testing frameworks such as XUnit and NUnit and is a straightforward and clean way of writing tests. For more information, please refer to here. 

How do you set the focus to an InputText element?

We can focus an InputText Blazor element not directly but by using JavaScript in Blazor. We can set an ID for the InputText and then pass it to JavaScript using interop by method InvokeVoidAsync. In the JavaScript function, use the focus DOM input method for focusing the input element with the received ID from Blazor. Refer to the following code snippet. Refer the script file in the HTML page

How do you update a C# value in Blazor using JavaScript?

We can change a C# property’s value in Blazor from JavaScript by invoking the method DotNet.invokeMethodAsync in the script file (.js file). It takes the parameters Assembly name (Application name), the method name (public static method), and method parameter where we can change the C# static parameter. Refer to the following code snippet for more details. Refer the script file in the HTML page In the previous example, we have changed the ParaContent C# field value from the JavaScript by calling the static method ChangeParaContentValue from JavaScript, along with the new value as one of parameters in invokeMethodAsync. The C# method should be defined as static and it should have a JSInvokable attribute. The arguments in the JavaScript method Dotnet.invokeMethodAsync should be InvokeFromJsApp—AssemblyName. ChangeParaContentValue—C# JSInvokable static method name. “New Content”—method arguments. You can download the reference sample here.