4 Replies - 3965 Views - Last Post: 23 July 2012 - 11:14 PM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

bgcolor vs style("background-color")

Posted 23 July 2012 - 06:28 PM

I have a really simple question here yet I do not really know the answer.

I have a table which rows are to have different background colors so, after binding, I am dynamically changing the background colors.

I had no problem doing this. I used the bgcolor property and it works. Now, another page does the same. When I am working in another page, I thought of style("background-color") and it works fine.

Now, I just want to know if there are difference in performance regarding the two properties. Which is more appropriate to use between the two? Is one faster than the other?

Is This A Good Question/Topic? 0
  • +

Replies To: bgcolor vs style("background-color")

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,289
  • Joined: 18-April 07

Re: bgcolor vs style("background-color")

Posted 23 July 2012 - 09:41 PM

I don't believe there is any performance difference. Styling itself isn't like programming where performance is an issue at all.

Now as far as which one is more appropriate, they say that you should try to use CSS styling whenever possible. bgcolor is a bit of a legacy method. It is like <font>. You don't really use it any more.

So I would suggest you use the styling method. Then make sure the actual styling is in an external style (that is, in an external stylesheet you link into the page) and use "class" in the actual elements. This is going to allow you to change the color in one spot and have it change several elements simultaneously.

Hope this answered your question. :)

This post has been edited by Martyr2: 23 July 2012 - 09:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 Maheadams  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 28-July 11

Re: bgcolor vs style("background-color")

Posted 23 July 2012 - 10:02 PM

View PostNovember-06, on 24 July 2012 - 06:58 AM, said:

I have a really simple question here yet I do not really know the answer.

I have a table which rows are to have different background colors so, after binding, I am dynamically changing the background colors.

I had no problem doing this. I used the bgcolor property and it works. Now, another page does the same. When I am working in another page, I thought of style("background-color") and it works fine.

Now, I just want to know if there are difference in performance regarding the two properties. Which is more appropriate to use between the two? Is one faster than the other?


Using properties in tag style, CSS is better. Try to use ID or CLASS for background style.

#background{
background-image:url(image.jpg);
background-color:#fff;
position:absolute;
}

I think this is what you're looking for

This post has been edited by Maheadams: 23 July 2012 - 10:06 PM

Was This Post Helpful? 0
  • +
  • -

#4 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

Re: bgcolor vs style("background-color")

Posted 23 July 2012 - 10:51 PM

Thanks for the answer. I want to ask another question though.

If I have a repeater or a gridview which purpose is only to display readonly data that will not be edited or anything other than be read, should I add labels to hold data on binding or should I just used inline codings of eval?

Say... which is better?
<asp:repeater id="rpt" runat="server">
   <HeaderTemplate><table></HeaderTemplate>
   <ItemTemplate>
     <tr>
        <td>
           <asp:label id="lbl" runat="server" text='<%#Eval("txtColumn")%>'></asp:label>
        </td>
     </tr>
   </ItemTemplate>
   <FooterTemplate></table></FooterTemplate>
</asp:repeater>


or
<asp:repeater id="rpt" runat="server">
   <HeaderTemplate><table></HeaderTemplate>
   <ItemTemplate>
     <tr>
        <td>
           <%#Eval("txtColumn")%>
        </td>
     </tr>
   </ItemTemplate>
   <FooterTemplate></table></FooterTemplate>
</asp:repeater>


This post has been edited by November-06: 23 July 2012 - 10:53 PM

Was This Post Helpful? 0
  • +
  • -

#5 Maheadams  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 28-July 11

Re: bgcolor vs style("background-color")

Posted 23 July 2012 - 11:14 PM

2nd one is better i guess, U can add multiple column like <td><%# Eval("Column1") %></td><td><%# Eval("Column2") %></td>

and you can also use a repeater with table layout.

If its helpful please do 'vote this post up'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1