Home All Groups Group Topic Archive Search About
Author
14 Jun 2006 5:14 PM
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

Author
14 Jun 2006 8:23 PM
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


Show quoteHide quote
On Wed, 14 Jun 2006 19:14:54 +0200, "Bob" <s**@sdvsd.dc> wrote:

>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
Author
15 Jun 2006 2:52 PM
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

Show quoteHide quote
"Christoph Richter [AT]" <christ***@richter.md.N0Spam> wrote in message
news:tqr0921fe8e0b76m6tan1lecerbdrfuc1j@4ax.com...
> 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
>
>
> On Wed, 14 Jun 2006 19:14:54 +0200, "Bob" <s**@sdvsd.dc> wrote:
>
> >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