This is a migrated thread and some comments may be shown as answers.

Enable TextBox based on CheckBox value

2 Answers 1136 Views
Checkbox
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Veteran
Jonathan asked on 02 May 2020, 09:26 PM

Hi

How do I disable / enable a Telerik TextBox based on the value of CheckBox - and when the value changes?

Use ValueChanged?  How do I reference my TextBox  'WaterNotes" control?  

 

                 <TelerikCheckBox ValueChanged="@((bool value) => ValueChanged(value))" id="water" class="form-control" style="width: 50px;" Value="Customer.Water" />
     

        <ITelerikTextBoxid="WaterNotes" class="form-control" style="height: 40px;"  Value="Customer.WaterNotes" />

 

    private void ValueChangedWaterSink(bool value)
    {
        if (value)
            ???????
      
    }

 

Thx Again

2 Answers, 1 is accepted

Sort by
0
Accepted
Svetoslav Dimitrov
Telerik team
answered on 04 May 2020, 12:49 PM

Hello Jonathan,

You can use the @bind-Value (two-way data binding) for the TelerikCheckBox and bind the Enabled parameter of the TelerikTextBox to the same bool variable. I have made a small code snippet to illustrate that:

<p>
    <label for="toggleTextbox">Enable/Disable Texbox</label>
    <TelerikCheckBox Id="toggleTextbox" @bind-Value="isEnabled"></TelerikCheckBox>
</p>

<TelerikTextBox @bind-Value="userInput" Enabled="isEnabled"></TelerikTextBox>

@if (!String.IsNullOrEmpty(userInput))
{
    <p>
        The user input is: <strong>@userInput</strong>
    </p>
}

@code {
    public bool isEnabled { get; set; }
    public string userInput { get; set; } = String.Empty;
}

Regards
Svetoslav Dimitrov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Jonathan
Top achievements
Rank 1
Veteran
answered on 06 May 2020, 01:55 PM
thx again!
Tags
Checkbox
Asked by
Jonathan
Top achievements
Rank 1
Veteran
Answers by
Svetoslav Dimitrov
Telerik team
Jonathan
Top achievements
Rank 1
Veteran
Share this question
or