can get forecolor but not background color in Javascript

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

  1. Bob

    Bob Guest

    Hi,

    When clicked into any cell of the table, i want to get the background color
    of it. I can get the forecolor but not the bakground color (gives an empty
    Alert, no error).
    I think i can't change anything in the code-behind, so the error will be in
    the javascript code ...

    Thanks for your help
    Bob

    the aspx file:
    -----------
    <asp:Table ID="table1" runat="server"> </asp:Table>

    <script language="javascript" type="text/javascript">
    function tableclick(event)
    {
    forecl=window.event.srcElement.style.color
    // this works
    backcl=window.event.srcElement.style.background //
    this not
    alert(forecl)
    alert(backcl)}
    }

    the code-behind:
    ----------------
    'creattion of the cells in the table
    Dim r As TableRow
    Dim c(50, 20) As TableCell
    For i = 0 To 50
    r = New TableRow()
    For j = 0 To 20
    c(i, j) = New TableCell()
    r.Cells.Add(c(i, j))
    Next
    Table1.Rows.Add(r)
    Next
    ....
    //e.g. the back/forecolor of cell 3,2:
    c(3, 2).BackColor = System.Drawing.ColorTranslator.FromHtml("red")
    c(3, 2).ForeColor = System.Drawing.ColorTranslator.FromHtml("yellow")
    //c(3, 2).BackColor = Drawing.Color.Red
    // tried also with this method
    ....
    Bob, Jun 17, 2006
    #1
    1. Advertising

  2. "Bob" <> wrote in
    news::

    > When clicked into any cell of the table, i want to get the background
    > color of it. I can get the forecolor but not the bakground color
    > (gives an empty Alert, no error).
    > I think i can't change anything in the code-behind, so the error will
    > be in the javascript code ...


    It's not possible to read the default style properties of a DOM element.
    They'll always return 'undefined' or whatever passes for that in
    JavaScript.


    --
    Klaus H. Probst, MVP
    http://www.simulplex.net/
    Klaus H. Probst, Jun 17, 2006
    #2
    1. Advertising

  3. Bob

    Bob Guest

    Thanks, but then, how do you explain it works with the forecolor?
    There must be a way to do the same with the background ...

    "Klaus H. Probst" <> wrote in message
    news:Xns97E519D47DEE945F9BC4070F84482B8A8@207.46.248.16...
    > "Bob" <> wrote in
    > news::
    >
    > > When clicked into any cell of the table, i want to get the background
    > > color of it. I can get the forecolor but not the bakground color
    > > (gives an empty Alert, no error).
    > > I think i can't change anything in the code-behind, so the error will
    > > be in the javascript code ...

    >
    > It's not possible to read the default style properties of a DOM element.
    > They'll always return 'undefined' or whatever passes for that in
    > JavaScript.
    >
    >
    > --
    > Klaus H. Probst, MVP
    > http://www.simulplex.net/
    >
    Bob, Jun 17, 2006
    #3
  4. Bob

    Randy Webb Guest

    Bob said the following on 6/17/2006 4:59 AM:
    > Hi,
    >
    > When clicked into any cell of the table, i want to get the background color
    > of it. I can get the forecolor but not the bakground color (gives an empty
    > Alert, no error).
    > I think i can't change anything in the code-behind, so the error will be in
    > the javascript code ...


    <snip>

    > backcl=window.event.srcElement.style.background //


    window.event.srcElement.style.backgroundColor;

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Jun 17, 2006
    #4
  5. Bob

    André Guest

    thanks

    "Randy Webb" <> wrote in message
    news:D...
    > Bob said the following on 6/17/2006 4:59 AM:
    > > Hi,
    > >
    > > When clicked into any cell of the table, i want to get the background

    color
    > > of it. I can get the forecolor but not the bakground color (gives an

    empty
    > > Alert, no error).
    > > I think i can't change anything in the code-behind, so the error will be

    in
    > > the javascript code ...

    >
    > <snip>
    >
    > > backcl=window.event.srcElement.style.background //

    >
    > window.event.srcElement.style.backgroundColor;
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices -

    http://www.JavascriptToolbox.com/bestpractices/
    André, Jun 18, 2006
    #5
    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. manoj kumar via .NET 247

    Dot Net Cell Color forecolor change

    manoj kumar via .NET 247, Mar 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    517
    manoj kumar via .NET 247
    Mar 15, 2005
  2. Bob
    Replies:
    4
    Views:
    10,240
    André
    Jun 18, 2006
  3. Replies:
    3
    Views:
    1,440
  4. fig000
    Replies:
    0
    Views:
    4,529
    fig000
    Sep 6, 2004
  5. Replies:
    1
    Views:
    257
    marss
    Feb 14, 2007
Loading...

Share This Page