Change Textbox Background color in code

HI,
My project is using C#, Blazor Server. I have a Textbox that I need to be able to set different background / Text colors in code.

Does anyone have examples of select the Textbox and changing its properties dynamically?

Thanks

Hi @RicVA,

You can use the style attribute of RadzenTextBox like this:

<RadzenTextBox 
  style="@($"--rz-input-background-color: {background}; --rz-input-value-color: {color}")"  
/>
@code {
   string background = "red";
   string color = "white";
}

Explanation:

  1. $"--rz-input-background-color: {background}; --rz-input-value-color: {color}" is a C# string interpolation to prevent the notorious Blazor exception that one cannot mix expressions and strings.
  2. --rz-input-background-color and --rz-input-value-color are CSS variables that RadzenTextBox uses for styling.
2 Likes