I am experiencing this problem with version 2.29 when the dropdown list is in a "component"
It seems to be intermittent but dependent on how long the async method takes to complete.
Edit page
@page "/"
@using System.Diagnostics
@using System.Threading
@using BlazorApp1.Components
<h1>Hello, world!</h1>
<EditForm class="form-inline" Model="@Model">
<MyComponent />
</EditForm>
Welcome to your new app.
@code {
object Model = new();
private Guid InstanceId;
public Index()
{
InstanceId = Guid.NewGuid();
Debug.WriteLine($"Index - {InstanceId}");
}
protected override Task OnInitializedAsync()
{
Debug.WriteLine("Index - OnInitializedAsync");
return base.OnInitializedAsync();
}
protected override Task OnParametersSetAsync()
{
Debug.WriteLine("Index - OnParametersSetAsync");
return base.OnParametersSetAsync();
}
}
Component
@using System.Diagnostics
<h3>My Component</h3>
<br />
<TelerikDropDownList @bind-Value=_selectedValue Data="@myComboData" TextField="MyTextField" ValueField="MyValueField" TValue="int" TItem="MyDdlModel"></TelerikDropDownList>
<br />
<TelerikButton OnClick="@SayHelloHandler" Primary="true">Say Hello</TelerikButton><br />
@helloString
<br />
@code {
private Guid InstanceId;
MarkupString helloString;
int _selectedValue { get; set; } = 2; // Preselected value
IEnumerable<MyDdlModel> myComboData { get; set; } = Enumerable.Empty<MyDdlModel>();
void SayHelloHandler()
{
string msg = string.Format("Hello from <strong>Telerik Blazor</strong> at {0}.<br /> Now you can use C# to write front-end!", DateTime.Now);
helloString = new MarkupString(msg);
}
public MyComponent()
{
InstanceId = Guid.NewGuid();
Debug.WriteLine($"MyComponent - {InstanceId}");
}
protected override async Task OnInitializedAsync()
{
Debug.WriteLine("MyComponent - OnInitializedAsync");
myComboData = await LoadData();
await base.OnInitializedAsync();
}
protected override Task OnParametersSetAsync()
{
Debug.WriteLine("MyComponent - OnParametersSetAsync");
return base.OnParametersSetAsync();
}
private async Task<IEnumerable<MyDdlModel>> LoadData()
{
await Task.Delay(100);
return Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
}
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
}