jeudi 20 février 2020

Remain Enabled Textbox To enabled After Page Postback in Repeater

I am using Repeater in my .aspx page binded with Database. There are 3 columns first is checkBox,SubjectName and Textbox. Initially textbox's are enable to false. there is a js function on checkbox to enable it's corresponding textbox. After postback enabled textbox gets disabled again. How should I retain the enabled Textbox to it's enabled state after postback?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../assets/js/jquery.min.js"></script>
    <script type="text/javascript"> 

        $(function () {
            //Enable Disable TextBoxes in a Row when the Row CheckBox is checked.
            $("[id*=chkRow]").bind("click", function () {
                //Find and reference the GridView.
                var grid = $(this).closest("table");

                //Find and reference the Header CheckBox.
                var chkHeader = $("[id*=chkHeader]", grid);

                //If the CheckBox is Checked then enable the TextBoxes in thr Row.
                if (!$(this).is(":checked")) {
                    var td = $("td", $(this).closest("tr"));
                    //td.css({ "background-color": "#FFF" });
                    $("input[type=text]", td).val = null;
                    $("input[type=text]", td).attr("disabled", "disabled");
                } else {
                    var td = $("td", $(this).closest("tr"));
                    //td.css({ "background-color": "#D8EBF2" });
                    $("input[type=text]", td).removeAttr("disabled");
                }

                //Enable Header Row CheckBox if all the Row CheckBoxes are checked and vice versa.
                if ($("[id*=chkRow]", grid).length == $("[id*=chkRow]:checked", grid).length) {
                    chkHeader.attr("checked", "checked");
                } else {
                    chkHeader.removeAttr("checked");
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <center>
        <div>
             <asp:Repeater ID="repeatersubjectwiserpt" runat="server" DataSourceID="SqlDataSource2Getsubjects">
                                            <HeaderTemplate>
                                                <table class="table">
                                                    <thead class="thead-light">
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Subjects</th>
                                                            <th>No. Of Vaccancy</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <tr>
                                                    <td>
                                                        <asp:CheckBox ID="chkRow" runat="server" Style="padding: 4px;" /></td>
                                                    <td><%# Server.HtmlEncode(Eval("subname") as string) %>
                                                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Server.HtmlEncode(Eval("id") as string) %>' />
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="textboxnoofvaccancy" runat="server" Enabled="false" CssClass="form-control" ClientID="textboxnoofvaccancy" MaxLength="3"></asp:TextBox></td>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator16" runat="server" ErrorMessage="*Required" SetFocusOnError="true" Display="Dynamic" ControlToValidate="textboxnoofvaccancy" InitialValue="0" ValidationGroup="" ForeColor="Red" Font-Italic="true" Font-Size="11px" EnableClientScript="true"></asp:RequiredFieldValidator>
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator7" runat="server" ErrorMessage="Only Numbers Max. 3 Digit" ValidationExpression="(^([0-9]*|\d*\d{1,3}?\d*)$)" SetFocusOnError="true" Display="Dynamic" ControlToValidate="textboxnoofvaccancy" ValidationGroup="" ForeColor="Red" Font-Italic="true" Font-Size="11px" EnableClientScript="true"></asp:RegularExpressionValidator>
                                                </tr>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                </tbody>
                                                      </table>
                                            </FooterTemplate>
                                        </asp:Repeater>
                                        <asp:SqlDataSource ID="SqlDataSource2Getsubjects" runat="server" ConnectionString="<%$ ConnectionStrings:schoolmasterdbconstr %>" SelectCommand="SELECT [subject_id] as 'id',[subject_name] as 'subname' FROM [subject_master] order by subject_name asc"></asp:SqlDataSource>
        </div>


        <asp:Button ID="Button1" runat="server" Text="Button" /></center>
    </form>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire