Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on a form which is having a gridview & save button.Gridview has a checkbox & a textbox.If i clicked on checkbox and if it is checked,the textbox in that row becomes disable and if it is unchecked,the textbox in that row becomes enable.For this purpose i'm using following JQuery code & it is working properly.

JavaScript
$(document).ready(function () {
    try {
        $("input[type=checkbox][id*=chkChild]").click(function () {
            if (this.checked) {
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").attr("disabled", true);
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").val("NA");
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").focus();
            } else {

                $(this).closest("tr").find("input[type=text][id*=txtRemark]").attr("disabled", false);
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").val("");
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").focus();
            }
        });
    } catch (e) {
        alert(e);
    }
});


But after postback if i the textbox is disabled then it is not retaining its disable state & it becomes enable. So please tell me how to maintain its state.
Posted
Updated 26-Sep-14 22:28pm
v2

1 solution

you can write a function to manipulate textbox accordingly checkbox inside grid and call that function in client side pageLoad function.
C#
function pageLoad()
{
EnableDisabletextBox();
}  
function EnableDisabletextBox()
{
try {
        $("input[type=checkbox][id*=chkChild]").each(function () {
            if (this.checked) {
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").attr("disabled", true);
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").val("NA");
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").focus();
            } else {

                $(this).closest("tr").find("input[type=text][id*=txtRemark]").attr("disabled", false);
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").val("");
                $(this).closest("tr").find("input[type=text][id*=txtRemark]").focus();
            }
        });
    } catch (e) {
        alert(e);
    } 
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900