change table cell style in vb code

Discussion in 'ASP .Net' started by Keith G Hicks, Mar 19, 2008.

  1. asp.net 2.0 using vwd

    I'm trying to chagne the border of a table cell in my vb code but cannot
    seem to do it. The cell has an ID of "tdAlert"

    If txtAlert.Text <> "" Then
    tdAlert.Style = "width: 547px; border-left-color: red;
    border-bottom-color:
    red; border-top-style: solid; border-top-color: red; border-right-style:
    solid; border-left-style: solid; border-right-color: red;
    border-bottom-style: solid;"
    Else
    tdAlert.Style = "width: 547px;"
    End If

    apparently tdAlert doesn't exist. I've saved the project thinking that maybe
    intellisense would not find it if I didn't save it with the new ID but that
    didnt' solve the problem. Any ideas on how this can be done? I just need a
    red border around the cell under certain conditions.

    Thanks,

    Keith
     
    Keith G Hicks, Mar 19, 2008
    #1
    1. Advertising

  2. "Keith G Hicks" <> wrote in message
    news:...
    > asp.net 2.0 using vwd
    >
    > I'm trying to chagne the border of a table cell in my vb code but cannot
    > seem to do it. The cell has an ID of "tdAlert"
    >
    > If txtAlert.Text <> "" Then
    > tdAlert.Style = "width: 547px; border-left-color: red;
    > border-bottom-color:
    > red; border-top-style: solid; border-top-color: red;

    border-right-style:
    > solid; border-left-style: solid; border-right-color: red;
    > border-bottom-style: solid;"
    > Else
    > tdAlert.Style = "width: 547px;"
    > End If
    >
    > apparently tdAlert doesn't exist. I've saved the project thinking that

    maybe
    > intellisense would not find it if I didn't save it with the new ID but

    that
    > didnt' solve the problem. Any ideas on how this can be done? I just need a
    > red border around the cell under certain conditions.
    >



    In order to access the td as ASP.NET control it needs, in addition to an id
    attribute, a runat="server" attribute. This makes it a HtmlTableCell.

    You can not assign a style string directly since its an instance of
    CssStyleCollection. This isn't a good approach anyway. A css class would
    be better. The HtmlTableCell doesn't expose a CssClass attribute so you
    need to add it via the Attributes collection.

    The HtmlTableCell has a Width property so you can assign the 547px width to
    that property.

    Add the following mark up to your <head>:-

    <style type="text/css">
    td.highlight {border:1px solid red;}
    </style>

    Then your code becomes:-

    If txtAlert.Text <> "" Then

    tdTest.Attributes.Add("class", "highlight");

    Else

    tdTest.Attributes.Remove("class");

    End If



    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Mar 19, 2008
    #2
    1. Advertising

  3. Show how you define tdAlert in the .aspx page.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Keith G Hicks" <> wrote in message
    news:...
    > asp.net 2.0 using vwd
    >
    > I'm trying to chagne the border of a table cell in my vb code but cannot
    > seem to do it. The cell has an ID of "tdAlert"
    >
    > If txtAlert.Text <> "" Then
    > tdAlert.Style = "width: 547px; border-left-color: red;
    > border-bottom-color:
    > red; border-top-style: solid; border-top-color: red;
    > border-right-style:
    > solid; border-left-style: solid; border-right-color: red;
    > border-bottom-style: solid;"
    > Else
    > tdAlert.Style = "width: 547px;"
    > End If
    >
    > apparently tdAlert doesn't exist. I've saved the project thinking that
    > maybe
    > intellisense would not find it if I didn't save it with the new ID but
    > that
    > didnt' solve the problem. Any ideas on how this can be done? I just need a
    > red border around the cell under certain conditions.
    >
    > Thanks,
    >
    > Keith
    >
    >
     
    Eliyahu Goldin, Mar 19, 2008
    #3
  4. Thanks Anthony. That worked. But I had to do some more research because I
    still was unable to access my table cell in code:

    http://www.velocityreviews.com/forums/t372741-how-to-access-html-controls-fr
    om-code-behind-.html (Imports
    System.Web.UI.HtmlControls)

    Works fine now.

    Keith

    "Anthony Jones" <> wrote in message
    news:...
    >
    > "Keith G Hicks" <> wrote in message
    > news:...
    > > asp.net 2.0 using vwd
    > >
    > > I'm trying to chagne the border of a table cell in my vb code but cannot
    > > seem to do it. The cell has an ID of "tdAlert"
    > >
    > > If txtAlert.Text <> "" Then
    > > tdAlert.Style = "width: 547px; border-left-color: red;
    > > border-bottom-color:
    > > red; border-top-style: solid; border-top-color: red;

    > border-right-style:
    > > solid; border-left-style: solid; border-right-color: red;
    > > border-bottom-style: solid;"
    > > Else
    > > tdAlert.Style = "width: 547px;"
    > > End If
    > >
    > > apparently tdAlert doesn't exist. I've saved the project thinking that

    > maybe
    > > intellisense would not find it if I didn't save it with the new ID but

    > that
    > > didnt' solve the problem. Any ideas on how this can be done? I just need

    a
    > > red border around the cell under certain conditions.
    > >

    >
    >
    > In order to access the td as ASP.NET control it needs, in addition to an

    id
    > attribute, a runat="server" attribute. This makes it a HtmlTableCell.
    >
    > You can not assign a style string directly since its an instance of
    > CssStyleCollection. This isn't a good approach anyway. A css class would
    > be better. The HtmlTableCell doesn't expose a CssClass attribute so you
    > need to add it via the Attributes collection.
    >
    > The HtmlTableCell has a Width property so you can assign the 547px width

    to
    > that property.
    >
    > Add the following mark up to your <head>:-
    >
    > <style type="text/css">
    > td.highlight {border:1px solid red;}
    > </style>
    >
    > Then your code becomes:-
    >
    > If txtAlert.Text <> "" Then
    >
    > tdTest.Attributes.Add("class", "highlight");
    >
    > Else
    >
    > tdTest.Attributes.Remove("class");
    >
    > End If
    >
    >
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET
    >
    >
     
    Keith G Hicks, Mar 20, 2008
    #4
    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. Shiperton Henethe
    Replies:
    5
    Views:
    1,172
    Adrienne
    Sep 19, 2003
  2. Phillip Roncoroni
    Replies:
    14
    Views:
    1,145
    Toby A Inkster
    Apr 5, 2004
  3. Jonathan N. Little
    Replies:
    3
    Views:
    481
    Toby A Inkster
    Mar 4, 2007
  4. Ken Varn
    Replies:
    0
    Views:
    539
    Ken Varn
    Apr 26, 2004
  5. Cylix
    Replies:
    0
    Views:
    123
    Cylix
    Jun 13, 2006
Loading...

Share This Page