Enable TextBox based on CheckBox value

3 posts, 1 answers
  1. Jonathan
    Jonathan avatar
    116 posts
    Member since:
    Jan 2014

    Posted 02 May Link to this post

    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. Answer
    Svetoslav Dimitrov
    Admin
    Svetoslav Dimitrov avatar
    96 posts

    Posted 04 May Link to this post

    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.
  3. Jonathan
    Jonathan avatar
    116 posts
    Member since:
    Jan 2014

    Posted 06 May in reply to Svetoslav Dimitrov Link to this post

    thx again!
Back to Top