Element reference is null for TelerikComboBox

1 Answer 46 Views
ComboBox
PalmSens
Top achievements
Rank 1
PalmSens asked on 16 Jan 2025, 01:23 PM

I'm trying to reference a TelerikComboBox in a razor component, but it keeps returning null.
(I'm using version 6.2.0)

Any clues?

Html:

<TelerikComboBox Class="hide-combobox-buttons" 
                 Data="@AllLabels" 
                 Value="@Label"
                 @ref="ComboBoxRef"
                 ValueChanged="@((string newValue)=> ValueChanged(newValue))"
                 AllowCustom="true">
</TelerikComboBox>

 

@code{

 private TelerikComboBox<string, string>? ComboBoxRef { get; set; }

 [Parameter]
 public IReadOnlyList<string>? AllLabels { get; set; }

 private string Label { get; set; } = string.Empty;

 protected override async Task OnInitializedAsync()
 {
     if (ComboBoxRef != null) //here it's always null
         await ComboBoxRef.FocusAsync();

     await base.OnInitializedAsync();
 }

}

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 16 Jan 2025, 02:21 PM

Hello,

Blazor component references are available in OnAfterRender and OnAfterRenderAsync, not earlier.

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox
Asked by
PalmSens
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or