Skip to content Skip to sidebar Skip to footer

Retain Textbox Value When Checkbox Is Checked

I have a set of TextBox that will automatically compute the 'total' based on 'gross amount' (user input). Each text box has a condition that is based on another text box. My comp

Solution 1:

First of all, to provide client-side capability for DevExpress textbox controls you need to set ClientInstanceName attribute as the textbox client ID:

<dx:ASPxTextBoxID="txtbx_add"runat="server"Width="170px"Theme="Material"ClientInstanceName="txtbx_add">
...
</dx:ASPxTextBox>

Since ASP.NET standard checkbox control provided in the sample doesn't specify ClientIDMode="Static" attribute, it assumed to have pre-assigned ClientID so that client-side event uses checkbox click trigger given below:

$(document).ready(function () {

    // other stuff// get current DX textbox value// this value should be stored before using checkbox click eventvar value = txtbx_add.GetText(); // or use GetValue()

    $('#<%= chckbox_nonvat.ClientID %>').click(function () { 
        if ($(this).is(':checked')) {
            txtbx_add.SetText(0); // if checked, set to 0
        } else {
            txtbx_add.SetText(value); // if unchecked, set to previous state
        }
    });

    // other stuff
}

NB: You can substitute $(this).is(':checked') to $(".checkbox").is(':checked') if you're sure there is only one checkbox at the page defined by CssClass="checkbox".

References:

jquery check if asp checkbox is checked

ASPxClientTextEdit.SetText (DevExpress Documentation)

Post a Comment for "Retain Textbox Value When Checkbox Is Checked"