简体   繁体   English

如何在asp.net中回发后保留文本框的状态

[英]How to retain Textbox's State after Postback in asp.net

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. 我正在处理一个带有gridview和保存按钮的表单。Gridview有一个复选框和一个文本框。如果我单击了该复选框并被选中,则该行中的文本框将被禁用,如果未选中,则该文本框为此,我正在使用以下JQuery代码,并且该代码正常工作。

$(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. 因此,请告诉我如何保持其状态。

I think there are two options: 我认为有两种选择:
1) Call your Jquery function after each page postback, but making a loop in each line of the gridview and read the checkbox (checked or not). 1)在每个页面回发之后调用Jquery函数,但是在gridview的每一行中循环并读取复选框(是否选中)。 It would be call the function you did but for each grid line. 它将被称为您所做的函数,但对于每条网格线。
2) Doing this function in the server side code. 2)在服务器端代码中执行此功能。 But I believe that is not your intention. 但我相信这不是您的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM