ASP.NET ClientID DataGrid Returning Null

I see that there were a lot of questions about getting ClientID in ASP.NET, but all the questions I looked did not help for my scenario. I'm a little new to ASP.NET and have problems getting the ClientID DataGrid in JavaScript.

Hope someone in this forum helps me find a way.

On my aspx page, I have a datagrid:

 <div class="tblgrid" id="divItems">
    <asp:DataGrid ID="dgItems" runat="server" AutoGenerateColumns="False" GridLines="None">
    <Columns>
         <asp:BoundColumn HeaderText="EmpId" DataField="EmpId">
         </asp:BoundColumn>
         <asp:BoundColumn HeaderText="F_Name" DataField="F_Name">
         </asp:BoundColumn>
         <asp:BoundColumn HeaderText="L_Name" DataField="L_Name">
         </asp:BoundColumn>
         <asp:BoundColumn DataField="City" HeaderText="City">
         </asp:BoundColumn>
         .....
    </Columns>

When I use the following in my JavaScript, it returns the corresponding HTML code for the table in the warning message.

  alert(document.getElementById('ct100_PageContent_dgItems').innerHTML);

but when I use the ASP.NET client ID, I get an exception with a null value because it throws a null value.

  alert(document.getElementById('<%=dgItems.ClientID %>').innerHTML); 

Can anyone help me in this regard.

Thanks in advance.

+4
2

document.getElementById('<%=dgItems.ClientID %>') JS aspx, ASP.Net . , .aspx.

, DataGrid , ClientIDMode="static":

<asp:DataGrid ID="dgItems" ClientIDMode="static" runat="server" AutoGenerateColumns="False" GridLines="None">

document.getElementById('dgItems')
+1

alert(document.getElementById('<%=dgItems.ClientID %>').innerHTML);

.. DataGrid CSS, 'dgrid', jQuery, ?

0

Source: https://habr.com/ru/post/1657682/


All Articles