why does this not work?

B

Bob

Hi,

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

In the code-behind, i defined 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))
Next
Table1.Rows.Add(r)
Next

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)
{
strid=window.event.srcElement.id
colo=document.getElementById("table1").rows[2].cells[2]style.background
alert(colo)
}
document.getElementById("table1").onclick = tableclick
</script>

But the alert gives always an empty window.
Thanks for any help.
Bob
 
C

Christoph Richter [AT]

Hi,

The id you give an control is not the id, that it will have in the
client.

since you can have many controls, usercontrols in you page that have
controls with the same id. so the aspnet creates for the client code
some hirachial id's (in the format [ParentId]$[ParentId]$[YourId]).

after you added the control to you page (write it in the xml aspx file
or call this.Controls.Add()) you can access this client Id with the
Control.ClientId Property. pass that to your js and it should work.

cheers
christoph


Hi,

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

In the code-behind, i defined 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))
Next
Table1.Rows.Add(r)
Next

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)
{
strid=window.event.srcElement.id
colo=document.getElementById("table1").rows[2].cells[2]style.background
alert(colo)
}
document.getElementById("table1").onclick = tableclick
</script>

But the alert gives always an empty window.
Thanks for any help.
Bob

Cheers,
Christoph

Vienna/Austria

www.code4ward.net/blogs/cmn
 
B

Bob

Hi, Thanks for replying,

but i still don't know how to handle this.
i read a lot about ClientID etc ... but so far it remains unclear to me.
Would it be possible to give the code for my case?
Thanks again

Christoph Richter said:
Hi,

The id you give an control is not the id, that it will have in the
client.

since you can have many controls, usercontrols in you page that have
controls with the same id. so the aspnet creates for the client code
some hirachial id's (in the format [ParentId]$[ParentId]$[YourId]).

after you added the control to you page (write it in the xml aspx file
or call this.Controls.Add()) you can access this client Id with the
Control.ClientId Property. pass that to your js and it should work.

cheers
christoph


Hi,

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

In the code-behind, i defined 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))
Next
Table1.Rows.Add(r)
Next

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)
{
strid=window.event.srcElement.id
colo=document.getElementById("table1").rows[2].cells[2]style.background
alert(colo)
}
document.getElementById("table1").onclick = tableclick
</script>

But the alert gives always an empty window.
Thanks for any help.
Bob

Cheers,
Christoph

Vienna/Austria

www.code4ward.net/blogs/cmn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top