Search code examples
asp.netvb.netweb-controlsdisabled-control

Disable Certain controls such as textbox, textarea, dropdowns etc when a checkbox is checked in aspx page


I need to disable the certain controls in an aspx page such as textbox, textarea, dropdown etc when a checkbox is checked. The checkbox sets a flag in the database, if the flag is set to 1, then those specific controls will be uneditable, else it will be editable. What is the simplest and easiest way to achieve this? I am looking for concepts. Thanks in advance.


Solution

  • If you are retrieving data from database then you may put it in in you page load..

    for example:

    [this is only pseudo code]

    Dim F = FlagfromDatabase;
    
    If F = 1
        txtSample.enable = false
    else
        txtSample.enable = true
    

    in you checkbox event

    If checkbox.check = true
        set FlagInDatabase = 1
    else
        set FlagInDatabase = 0
    

    load your page to execute the page load event