Access Blazor controls from code

How do I access the Radzen Blazor components from code. For example I have a RadzenDropDownDataGrid and RadzenNumeric. I want to be able to get the current values for each of the controls from the OnClick event on a RadzenButton

Hi @ssomwm,

Welcome to the Radzen community!

To access a Radzen Blazor component (or any Blazor component) you need to use the @ref attribute:

<RadzenGrid TItem="Customer"  @ref="myGrid" />
<RadzenTextBox @ref="myTextBox" />
@code {
    RadzenGrid<Customer> myGrid;
    RadzenTextBox myTextBox;
}

However to access the component value it is recommended to use data-binding.

<RadzenTextBox @bind-Value="myTextBoxValue" />
@code {
   string myTextBoxValue = "some value"
}
1 Like

Thank you that was very helpful