473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Difference between <div> and <tr> tags in terms of speed

375 256MB
Hi,

I have two questions.

1. I have heard that replacing a <tr> <td> with <div> tags increases the rendering speed. Is it so, and if yes which speed does it increase, rendering speed or loading speed.

2. Is the main purpose of app_browser is to convert <tr><td> to <div> tags.



Kindly help

Regards

cmrhema
May 12 '09 #1
7 7923
balame2004
142 100+
You can not replace <td> and <tr> tags with <Div> or vice versa. <tr> tag creates a html row in a html table and <td> creates a html cell in a html row. But div creates a division (or place holder) where we can place someother html control. Don't get confuse <div> tag with html row tag.
May 12 '09 #2
cmrhema
375 256MB
Actually balame2004 what I meant to ask was, say u have a page in .net where all the controls are placed in table consisting of tr and td tags. Whereas I have another one where controls are placed in div tags only.

Will the one with div tags be more faster than the one with table
May 12 '09 #3
Frinavale
9,735 Expert Mod 8TB
It sounds like you've got a case of "div-itis" (someone once told me this too so don't feel bad)

You don't have to place controls in <div> tags at all if you don't need to group things together.

Especially with concerns to developing a .NET application. You're more likely to use a Panel (which actually renders as a <div> tag when it is sent to the browser) because you can access Panels in your C# or VB server code.

The only time you should be using tables is to display tabular data. This is stuff that should be displayed in a table... in other words, tables should not be used as a layout for displaying your control; CSS should be used instead.

Tables do take longer to load than <div>s but it's not so only a matter of loading speed that you should be concerned with. You should also consider accessibility and maintainability.

An Accessibility example:

If someone who was blind was using a text to speech application to view your web site and you were using a table to as lay out as such:
Expand|Select|Wrap|Line Numbers
  1. This is a paragraph that          This is another paragraph 
  2. should be displayed in            that is displayed in 
  3. Column 1 of the table.            column 2 of the table.
It would be read as:
"This is a paragraph that
This is another paragraph
should be displayed in
that is displayed in
Column 1 of the Table.
Column 2 of the table"

As you can see, using a table to display the web content wont make any sense to anyone using a text to speech reader.

A maintainability example:

It is a lot easier to change css style for elements to do things like make the content appear "above" the rest of the content if the data is not in a table, but in it's own group.
May 13 '09 #4
cmrhema
375 256MB
Actually Frinnvale, I came to know thro a web designer that instead of displaying anything into tables if its displayed in a div manner , the performance, (i think he meant rendering is faster). So in fact even in gridview for each and every row , the designer askd to cover with div and replace all the tr. Is it so?
May 13 '09 #5
Frinavale
9,735 Expert Mod 8TB
@cmrhema
You don't.
The GridView is meant to display Tabular data and so it dynamically creates a table that displays this data.

If your data is not supposed to be displayed in a table then consider using a different control, or creating your own control, to suit your needs.

If your data is supposed to be displayed in a table then you could continue to use the GridView. The GridView has paging capability. This means that if you wanted to reduce the load time you could reduce the number of rows displayed at one time and let the "page" to view the next/previous rows.

What is the data you're displaying?
How should it be displayed?
May 13 '09 #6
Frinavale
9,735 Expert Mod 8TB
You could consider using a Template Item to format the display of your data....but a Table will still be rendered if you use a GridView.

You could create your own Templated Control instead of using an existing ASP.NET control if you want. Then you can specify exactly what should be placed where and how without using tables (if you wish).

For example, here I've created a new Web User Control (named TemplatedUserControl).

This User Control has 2 properties:
  • one that accepts a template used to display the data,
  • and one that accepts a template used to edit the data.

This control has a private class "DataItem" which inherits from the Control class and implements the INamingContainer interface. This private class is used in order to display dynamic data using a unique name in the templated control.

The Control dynamically displays the data (which you can retrieve from a database but here I'm just using an Array of Strings) by dynamically creating instances of the DataItem class which is applied to the template(s) provided (using the 2 template properties I described earlier):

Expand|Select|Wrap|Line Numbers
  1. Public Partial Class TemplatedUserControl
  2.     Inherits System.Web.UI.UserControl
  3.     Private _editing As Boolean = False
  4.     Private m_messageTemplate As ITemplate = Nothing
  5.     Private m_messageEditTemplate As ITemplate = Nothing
  6.  
  7.  
  8.     <TemplateContainer(GetType(DataItem))> _
  9.     Public Property DataTemplate() As ITemplate
  10.         Get
  11.             Return m_messageTemplate
  12.         End Get
  13.         Set(ByVal value As ITemplate)
  14.             m_messageTemplate = value
  15.         End Set
  16.     End Property
  17.     <TemplateContainer(GetType(DataItem))> _
  18.    Public Property EditTemplate() As ITemplate
  19.         Get
  20.             Return m_messageEditTemplate
  21.         End Get
  22.         Set(ByVal value As ITemplate)
  23.             m_messageEditTemplate = value
  24.         End Set
  25.     End Property
  26.  
  27.   Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  28.  
  29.         Dim myData() As String = _
  30.         {"first record", "second record", "third record", "fourth record"}
  31.         Dim i As Integer
  32.  
  33.         If DataTemplate IsNot Nothing AndAlso _editing = False Then
  34.             For i = 0 To myData.Length - 1
  35.                 Dim container As New DataItem(i, myData(i))
  36.                 DataTemplate.InstantiateIn(theItem)
  37.                 Me.Controls.Add(theItem)
  38.             Next
  39.         ElseIf EditTemplate IsNot Nothing AndAlso _editing Then
  40.             For i = 0 To myData.Length - 1
  41.                 Dim theItem As New DataItem(i, myData(i))
  42.                 EditTemplate.InstantiateIn(theItem)
  43.                 Me.Controls.Add(theItem)
  44.             Next
  45.  
  46.         End If
  47.     End Sub
  48.  
  49.     Public Class DataItem
  50.         Inherits Control
  51.         Implements INamingContainer
  52.  
  53.         Private m_index As Integer
  54.         Private m_message As String
  55.         Friend Sub New(ByVal i As Integer, ByVal msg As String)
  56.             Me.Index = i
  57.             Me.Message = msg
  58.         End Sub
  59.  
  60.         Public Property Index() As Integer
  61.             Get
  62.                 Return m_index
  63.             End Get
  64.             Set(ByVal value As Integer)
  65.                 m_index = value
  66.             End Set
  67.         End Property
  68.  
  69.         Public Property Message() As String
  70.             Get
  71.                 Return m_message
  72.             End Get
  73.             Set(ByVal value As String)
  74.                 m_message = value
  75.             End Set
  76.         End Property
  77.     End Class
  78.  
  79. End Class
  80.  

Ok, so now we have a Templated Control.
To use this you would create an ASP page and add the control to it:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="ScratchPad.WebForm1" %>
  2.  
  3. <%@ Register TagPrefix="uc" TagName="TemplateTest" Src="~/TemplatedUserControl.ascx" %>
  4.  
  5.     <asp:Panel runat="server" id="contents" style="border: none;">
  6.             <div style="width:150px;float:left; text-align:center; font-weight:bold; border-bottom:solid 1px black;">Index</div>
  7.             <div style="width:150px;float:left; text-align:center;font-weight:bold; border-bottom:solid 1px black;">Message</div>
  8.             <div style="clear:both"></div>
  9.             <uc:TemplateTest ID="myTemplatedCtrl" runat="server">
  10.                 <datatemplate>
  11.                        <div style="width:150px;float:left;text-align:center"><asp:Literal runat="server" ID="textValue" Text="<%# Container.Index %>"></asp:Literal></div>
  12.                        <div style="width:150px;float:left;text-align:center"><asp:Literal runat="server" ID="indexValue" Text="<%# Container.Message %>"></asp:Literal></div>
  13.                        <div style="clear:both"></div>
  14.                 </datatemplate>
  15.                 <edittemplate>
  16.                     <div style="width:150px;float:left; text-align:center"><asp:TextBox runat="server" ID="Literal1" Text="<%# Container.Index %>"></asp:TextBox></div>
  17.                     <div style="width:150px;float:left;text-align:center"><asp:TextBox runat="server" ID="Literal2" Text="<%# Container.Message %>"></asp:TextBox></div>
  18.                     <div style="clear:both"></div>
  19.                 </edittemplate>
  20.             </uc:TemplateTest>
  21.     </asp:panel>

Notice the Templates that I've supplied to the instance of the template control (the TemplateTest control). These Templates are passed into the 2 properties I described above.

If the Templated Control is configured such that it is not in edit mode the content will be displayed as text in <div> tags that have styles to make the text appear as if in a table layout....otherwise the text displayed in TextBoxes within the <div> tags. (I didn't add a property to let you specify whether or not the Template Control is in edit mode....just change the private _edit variable member in the Templated Control to change which template is used)

All you have to do in the ASP page is call the DataBind method to bind the data retrieved in the Templated control to the template provided in the page:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         DataBind()
  3. End Sub
May 13 '09 #7
cmrhema
375 256MB
Thank you Frinnavale for in depth clarification
May 14 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
4
by: DMJ | last post by:
What is the difference between these two tags?
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
1
by: Alan Hoyle | last post by:
I was using a <table border> to generate borders around some info/images, and decided to follow the w3c guidelines and convert it to CSS boxes with borders since it wasn't really tabular data. ...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
5
by: D E | last post by:
Here is the problem. The following script/html code works in IE, not Netscape. The javascript portion produces the text to be dynamically written in the <A HREF="">HEREHEREHERE</A> portion... The...
4
by: David | last post by:
I attempted the following <div id="div" runat="server"> <tr><td></td></tr> <tr><td></td></tr> </div> This is to hide a group of rows depending on some business rules in my code behind.
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
4
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.