How to Read and Update Textbox value in Gridview on Row Button Click Using Jquery
There is a Gridview with textbox and button in each row. I am getting the value of textbox and another column. After that I am creating SHA512 of both values then again its need to update to the same password textbox on button clicked for that corresponding row.
How should I do this?
Below is the JQuery event I am using:
<script type="text/javascript">
$(function () {
$("[id*=grduserdetail]").find("[id*=btnpass]").click(function () {
//Reference the GridView Row.
var row = $(this).closest("tr");
var unm = row.find('.userid').text();
var pwd = row.find($('[id*=txtpass]')).val();
var pwdLength = false;
if (pwd.length >= 6)
pwdLength = true;
var hasUpperCase = /[A-Z]/.test(pwd);
var hasLowerCase = /[a-z]/.test(pwd);
var hasNumbers = /\d/.test(pwd);
var hasNonalphas = /[@#&!$%^&*()]/.test(pwd);
if (!((hasUpperCase + hasLowerCase + hasNumbers + hasNonalphas + pwdLength) > 4)) {
alert('Password must be 6 charaters long and contain one Upper case one lower case one digit and one special character !');
return false;
} else {
//$(this).prev()[0].value = SHA512(unm.text() + pwd.val());
pwd.value = SHA512(unm + pwd);
//document.getElementById("shhidden").value = SHA512(unm + pwd);
return true;
}
});
});
</script>
<asp:GridView ID="grduserdetail" runat="server" CssClass="gridfont" Width="100%" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="user_id" Height="21px">
<HeaderStyle VerticalAlign="Top" CssClass="gridfontmaroon" />
<RowStyle CssClass="gridfont" />
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="User Id">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%#Server.HtmlEncode(Eval("user_id").ToString()) %>' CssClass="userid"> </asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Change Password" HeaderStyle-Width="250px">
<ItemTemplate>
<asp:TextBox ID="txtpass" MaxLength="20" runat="server" Font-Size="0.8em" autocomplete="off" TextMode="Password" Style="left: 3px; position: relative; top: 0px"
Width="120px" AutoCompleteType="None" autofill="false"></asp:TextBox>
<asp:Button ID="btnpass" runat="server" Text="Change Password" CommandName="Reset" Width="120px" OnClick="btnpass_Click" OnClientClick="return validatePassword(this);" />
</ItemTemplate>
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Center" Width="25%" />
</asp:TemplateField>
<%--<asp:ButtonField CommandName="Reset" Text="Change Password" ButtonType="Button" CausesValidation="false" ValidationGroup="1" />--%>
</Columns>
</asp:GridView>