Handling Null vs String.Empty in RadzenTextBox

Hi,

I have a little question: I have ad data model (SQL Server) where a field (type string) of an entity may be NULL. So the field can contain NULL, String.Empty or any other string value.

In Razen, I have a TextBox control bound to that field using ${enityname.Fieldname} which works well. However, there is no way to (visually) determine if the value of the TextBox is NULL or String.Empty since it looks both the same.

Also, there is no way to set NULL back again, e.g. if I have a value "Text" set and delete these chars in the TextBox and hit "Save", Radzen stores String.Empty instead of NULL. But the when inital value is NULL and I change some other field of the entity and click "Save", the NULL value remians.

Is there any way the user can set "NULL" as value for a textbox (e.g. ComboBox has a little button allowing to set NULL).

Thanks for your help!

There is no way to do that in the TextBox component however you can have additional button next to the TextBox where you can set null to desired property value.

Ok thanks. That was what I was thining of as well...

However, it would really make sense to have a "AllowEmpty" or "AllowNull" property (bool) which will then enable a little [ X ] button inside the textbox when the mouse is hovering over it and when clicked, it changes the value to NULL. Maybe this is something you can implement in one of the next releases of your component suite.

Thanks a lot!

Distinguishing between null and empty string in the same input component is not possible, I'm afraid. You will never know what is the current value null or empty string if you delete manually or press eventual X clear button.

Hi @JustJoe,

Adding a X button to the TextBox has a few implications:

  1. It would require us to change the rendering by adding a wrapper HTML element. This is a breaking change that we would like to avoid.
  2. The X button would not render in two visually identical situations when the textbox is empty but its value is String.Empty and when it is empty and its value is null.

I would recommend against treating String.Empty and null as different things in your application.