Click here to Skip to main content
15,747,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview:
<asp:TemplateField HeaderText="First Name">
                                    <asp:Label ID="fNameLbl" Text='<%# Bind("fName") %>' runat="server"></asp:Label>
                                    <asp:TextBox ID="fNameTxtBox" Text='<%# Bind("fName") %>' runat="server"></asp:TextBox>
                                    <asp:Label ID="fNameErrorsLbl" CssClass="errorLabels" runat="server"></asp:Label>
                                    <asp:Button ID="editBtn" Text="Edit" CommandName="Edit" runat="server" />
                                    <asp:Button ID="updateBtn" Text="Update" CommandName="Update" runat="server" OnClientClick="checkGridView()" />
                                    <asp:Button ID="cancelBtn" Text="Cancel" CommandName="Cancel" runat="server" />

What I have tried:

I wanted to do so that when I click the update button to get the value from the cell in the row it was clicked to JS.

I tried this code:
function checkGridView() {
            fNameV = document.getElementById('fNameTxtBox');


But document.getElementById('fNameTxtBox') returns null. How can I fix it?
Updated 16-Apr-23 21:30pm

1 solution

You need to set the control's ClientIDMode property[^] to Static. Otherwise, the actual ID rendered in the HTML will be "mangled" with a combination of the IDs of its ancestors.
Share this answer

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