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


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:
JavaScript
function checkGridView() {
            fNameV = document.getElementById('fNameTxtBox');

            alert(fNameV);
        }


But document.getElementById('fNameTxtBox') returns null. How can I fix it?
Posted
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