Radzen Textbox Compoment binding Problem . #1018

Closed
opened 2026-01-29 17:47:50 +00:00 by claunia · 2 comments
Owner

Originally created by @tn-dev-fl on GitHub (Oct 24, 2023).

Describe the bug
After binding a value to with radzentextbox i get a Object reference not set to an instance of an object.

Required Step to reproduce
`
<RadzenTextBox @bind-Value="@ProductItem.ProductName" Change=@(args => OnChange(args, "TextBox")) Placeholder="Product ..." class="Textbox01" @onkeydown="OnTextBoxKeyDown" @ref="box">

public Product ProductItem = new Product();

private async Task OnTextBoxKeyDown(KeyboardEventArgs e)
{

	if (e.Key == "Enter" || e.Code == "NumpadEnter")
	{
		Search();
	}
}

public async void Search()
{
	condition = "1=1";

	condition = condition + " AND ProductName like '%" + ProductItem.ProductName.Replace("'", "") + "%'" + " OR (Bare_Code = '" + ProductItem.ProductName.Replace("'", "") + "')";
	//Console.WriteLine("cond is " + condition);
	Products = await ProductService.GetAllProduct(condition, "ProductName");
	StateHasChanged();

}
void OnChange(string value, string name)
{
	Console.WriteLine($"{name} value changed to {value}");
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
	if (firstRender)
	{
		await box.Element.FocusAsync();
	}
}

`
here is the video

vod

after some debugging i found out that on the first enter ProductItem.ProductName is empty after adding some Task.Delay in (OnTextBoxkeyDown) Function Somehow it manage to bind to the value
private async Task OnTextBoxKeyDown(KeyboardEventArgs e) { await Task.Delay(500); if (e.Key == "Enter" || e.Code == "NumpadEnter") { Search(); } }
vod

  • OS: [Windows]
  • Browser [chrome]
  • Version [4.16.4]
Originally created by @tn-dev-fl on GitHub (Oct 24, 2023). **Describe the bug** After binding a value to with radzentextbox i get a Object reference not set to an instance of an object. Required Step to reproduce ` <RadzenTextBox @bind-Value="@ProductItem.ProductName" Change=@(args => OnChange(args, "TextBox")) Placeholder="Product ..." class="Textbox01" @onkeydown="OnTextBoxKeyDown" @ref="box"></RadzenTextBox> public Product ProductItem = new Product(); private async Task OnTextBoxKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter" || e.Code == "NumpadEnter") { Search(); } } public async void Search() { condition = "1=1"; condition = condition + " AND ProductName like '%" + ProductItem.ProductName.Replace("'", "") + "%'" + " OR (Bare_Code = '" + ProductItem.ProductName.Replace("'", "") + "')"; //Console.WriteLine("cond is " + condition); Products = await ProductService.GetAllProduct(condition, "ProductName"); StateHasChanged(); } void OnChange(string value, string name) { Console.WriteLine($"{name} value changed to {value}"); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await box.Element.FocusAsync(); } } ` here is the video [vod](https://imgur.com/O8sgfwO) after some debugging i found out that on the first enter ProductItem.ProductName is empty after adding some Task.Delay in (OnTextBoxkeyDown) Function Somehow it manage to bind to the value ` private async Task OnTextBoxKeyDown(KeyboardEventArgs e) { await Task.Delay(500); if (e.Key == "Enter" || e.Code == "NumpadEnter") { Search(); } } ` [vod](https://imgur.com/a/wWeJwLT) - OS: [Windows] - Browser [chrome] - Version [4.16.4]
Author
Owner

@enchev commented on GitHub (Oct 24, 2023):

Hey @tn-dev-fl,

ProductItem is most probably null in your case. Please use our forum for such questions.

@enchev commented on GitHub (Oct 24, 2023): Hey @tn-dev-fl, ProductItem is most probably null in your case. Please use our forum for such questions.
Author
Owner

@tn-dev-fl commented on GitHub (Oct 24, 2023):

Hey @tn-dev-fl,

ProductItem is most probably null in your case. Please use our forum for such questions.

thank you for the reply . Can you elaborate why the binding didn't happen .

@tn-dev-fl commented on GitHub (Oct 24, 2023): > Hey @tn-dev-fl, > > ProductItem is most probably null in your case. Please use our forum for such questions. thank you for the reply . Can you elaborate why the binding didn't happen .
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1018