How to set the initial focus to a Blazor Numeric TextBox

Answer:

Set the initial focus to Numeric Textbox by using the create event. Please find the code snippet below.



<SfNumericTextBox @ref="NumericObj" TValue="int?" Value="@employee.EmpID">

<NumericTextBoxEvents TValue="int?" Created="@NumericCreated">NumericTextBoxEvents>

SfNumericTextBox>

@code{

SfNumericTextBox<int?> NumericObj;

public Employee employee = new Employee();

public int? Min { get; set; } = 1;



public class Employee

{

[Required(ErrorMessage = "Employee ID is required")]

public int? EmpID { get; set; }

}

public void NumericCreated()

{

this.NumericObj.FocusIn();

}

}


Loader.
Up arrow icon