-4

why document.getElementById("Table1")always give me null , I would use the function below to will add dynamically a column to the table Table1 you have ideas ? Thanks to better solutions. I work in aspx language vb.net

<%@ Page Title="Mapp" Language="VB" MasterPageFile="~/Site.Master"    AutoEventWireup="false"
CodeFile="Mappa.aspx.vb" Inherits="Mappa" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
    .style2
    {
        width: 409px;
    }
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server"   ContentPlaceHolderID="MainContent">

<!DOCTYPE html>
<html>

<head>
    <link href="Styles/MapStile.css" rel="stylesheet" type="text/css" />
  <script src="http://maps.googleapis.com/maps/api/js?"></script>
<asp:ScriptManager id="ScriptManager" runat="server"      EnablePageMethods="true" EnablePartialRendering="true"       EnableScriptGlobalization="true" EnableScriptLocalization="true" />
<script>

    function displayResult() {
        var table = document.getElementById("Table1");
        var row = table.insertRow(-1); // change to 0 to add at the top of the table
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        cell1.innerHTML = "R? C1";
        cell2.innerHTML = "R? C2";
    }

    google.maps.event.addDomListener(window, 'load', initialize);

</script>


</head>

<body >

    <Table ID="myTable" runat="server" Width="100%"> 
        <tr>
            <td>
                <Table id="Table1" runat="server" Width="100%"> 
                        <tr>
                           <td>  ciao </td>
                        </tr>
                        <tr>
                           <td>  ciao </td>
                        </tr>
                        <tr>
                           <td>  ciao </td>
                        </tr>
                        <tr>
                           <td>  ciao </td>
                        </tr>
                  </Table>  

            </td>
            <td> <div id="googleMap" style="float:right;width:960px;border:0.5px solid blue; height:600px;"></div  ></td>

        </tr>
    </Table>  
    <p><button type="button" onclick="displayResult()">Insert new row</button></p>
</body>

Andi AR
  • 2,678
  • 2
  • 23
  • 28
  • Do you mean `null`? Also, the rest of the question isn't really understandable. Is it the ASP that's adding the table to the DOM? – Andy Sep 17 '15 at 15:17
  • Please consider better formatting your question. Now, to the problem, where is your table element, with an id "Table1"? Is it dynamically generated? You have to be sure displayResult() is called when there is a "Table1" element present in your page. – adrield Sep 17 '15 at 15:18
  • 1
    possible duplicate of [getElementById not finding control generated by ASP.net](http://stackoverflow.com/questions/4595823/getelementbyid-not-finding-control-generated-by-asp-net) – LukeH Sep 17 '15 at 15:37

1 Answers1

0

Hope fully this post will solve your problem.

How to get element by id in javascript for server controls.

getElementById not finding control generated by ASP.net

Use this : document.getElementById('<%=Table1.ClientID %>');

Community
  • 1
  • 1
Andi AR
  • 2,678
  • 2
  • 23
  • 28
  • 2
    If you believe it's a duplicate, then flag the post. Don't answer it with a link to the other answer. – mason Sep 17 '15 at 16:10