why does this not work?

Discussion in 'ASP .Net Web Controls' started by Bob, Jun 14, 2006.

  1. Bob

    Bob Guest

    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
    Bob, Jun 14, 2006
    #1
    1. Advertising

  2. 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" <> 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
    Christoph Richter [AT], Jun 14, 2006
    #2
    1. Advertising

  3. Bob

    Bob Guest

    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 [AT]" <0Spam> wrote in message
    news:...
    > 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" <> 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
    Bob, Jun 15, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jblazi
    Replies:
    5
    Views:
    418
    jblazi
    Aug 16, 2004
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    441
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    851
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,733
    Smokey Grindel
    Dec 2, 2006
  5. Tarun
    Replies:
    5
    Views:
    380
    Tarun
    Jul 14, 2005
Loading...

Share This Page