In Blazor handle Blazor component InputNumber property readonly via code

308 views Asked by At
<InputNumber readonly 
             id="ProductShares"
             class="form-control" 
             placeholder="Product Shares"
             oninput="@Calculation"
             @bind-Value="product.ProductShares" />

I want to update InputNumber to readonly in code. That is on event oninput I am calling Calculation method and I want to programmatically update readonly property.

public async void Calculation(ChangeEventArgs e)
{
    // Something like
    if(condition)
    {
        ProductShares.readonly = true;  // ProductShares is the id of the InputNumber
    }
    else
    {
        ProductShares.readonly = false;
    }
}
1

There are 1 answers

0
Surinder Singh On BEST ANSWER

You can set bool value to readonly attribute like this

This is your html

<InputNumber readonly="@ReadOnly" 
             id="ProductShares"
             class="form-control" 
             placeholder="Product Shares"
             oninput="@Calculation"
             @bind-Value="product.ProductShares" />

This is your code behind

@code{
    private bool ReadOnly=true;
}