View Single Post
  #1 (permalink)  
Old June 15th, 2006, 12:05 PM
hertendreef hertendreef is offline
Friend of Wrox
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to get ID of server-control in Javascript?


In the aspx file, i create a table:
<asp:Table ID="table1" runat="server">

In the code-behind, i define a lot of cells with each an unique ID and some of them a background color (red):
Dim r As TableRow
Dim c(x,y) As TableCell
For i = 0 To x
r = New TableRow()
For j = 0 To y
c(i, j) = New TableCell()
c(i, j).ID = j & ":" & i.ToString
c(i,0).BackColor = System.Drawing.ColorTranslator.FromHtml("red")
r.Cells.Add(c(i, j))

The purpose is: when the user clicks in the table, the backgroundclor of the cell must be rendered which can generate some other action.
I did this in Javascript: (i want here the color of cell "2:2")
<script language="javascript" type="text/javascript">
function tableclick(event)
document.getElementById("table1").onclick = tableclick

But the alert gives always an empty window (no error).
Thanks for any help.

Reply With Quote