Rendering thousands of thumbnails table vs div vs span - html

My current code using tables to render thumbnails. When the page is resized, I use javascript to recalculate the number of rows and reinsert the cells into the correct columns.
This works fine for 100 thumbnails but is kind of slow when displaying 3000 thumbnails.
So I've looked at how bing displays its thumbnails and it appears to use span tags with display:inline-block. I've tested laying out thumbnails using span tags this has the benefit of automatically wrapping the thumbnails for me when I resize the page. I've also tested using DIV tags with float:left and it appears to be much slower than span on some browsers but not others.
However I'm wondering which method is typically fastest on all browsers for the kind of thumbnail layout i want.
a) Table
b) DIV tags with float:left
c) Span tags with display:inline-block
and in general do DIV tags render slower than span tags?

Of course the div / span solution will always be faster than the table solution because you don´t have to use javascript.
About the difference between span's, div's, floats and inline-blocks: I can´t imagine that there is a difference, but if there is, it will depend on the browser you´re using so you will have to test that in different browsers.

This may not be a direct answer to your question. But I would look at pagination. 3000 is a lot of records for one page. If you paginate (see YUI's carousel) you can reduce it down to 100 thumbnail chunks. Using the YUI pagination you could also allow the user to choose how many to put on one screen. Plus, the pagination does not need to do a server round trip if you don't want it too.

I would think that spans would load quicker but I have little substantial information on which to base this assumption. However, there is an approach you can take, I forget the term, but only content visible on the screen will load. Content that would need scrolling to be visible would not be loaded until it would be visible on the screen. This may help you speed up your loading.
Take a look at this link and it will give a script to do this loading technique: http://www.dynamicdrive.com/forums/showthread.php?p=200232

I created this script as a test:
<html>
<body>
<script type="text/javascript">
var i=0;
var startDate = Date();
for (i=0;i<=3000;i++)
{
document.write("<div style='float: left;display: inline;border: black 1px dotted; width: 100px; height: 100px;'>The number is " + i + "</div>");
}
var endDate = Date();
document.write("<br/>");
document.write("<strong>Started :</strong> " + startDate );
document.write("<br/><br/>");
document.write("<strong>Finished:</strong> " + endDate );
</script>
</body>
</html>
Switching to a span created no noticeable performance difference.
However, I know for a fact that IE has serious problems if you set the background to an image in a table cell or a DIV. It just doesn't render as fast. Not sure if that is how you are inserting the thumbnails.

Guys found some very interesting results. let me know if you can confirm. So I went extreme and tested with binding a 20,000 record xml to an asp.net listview to benchmark. very interesting.
this listview template which uses span
firefox: takes 10 seconds to render and refreshes/wraps immediately as page is resized. uses 367mb of memory
IE 8: takes 20 seconds to render and takes 10 seconds to wrap as page is resized. uses 605mb of memory.
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1" >
<LayoutTemplate>
<div runat="server" id="lstProducts">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
<ItemTemplate>
<span runat="server" style="display:inline-block">
<asp:Image runat="server" Style="width: 100px" enableviewstate="false" ID="ImageButton1" ImageUrl='<%# Eval("ImageUrl", "~/Photos/{0}") %>' />
<br />
<asp:Label ID="PropertyTypeLabel" runat="server" enableviewstate="false" Text='<%# Eval("PropertyType") %>' />
<br />
Bedrooms:
<asp:Label ID="BedroomsLabel" runat="server" enableviewstate="false" Text='<%# Eval("Bedrooms") %>' />
<br />
Town:
<asp:Label ID="TownLabel" runat="server" enableviewstate="false" Text='<%# Eval("Town") %>' />
<br />
Lat:
<asp:Label ID="LatLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lat") %>' />
<br />
Lon:
<asp:Label ID="LonLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lon") %>' />
<br />
Price:<asp:Label ID="PriceLabel" runat="server" enableviewstate="false" Text='<%# Eval("Price", "£{0}") %>' />
</span>
</ItemTemplate>
</asp:ListView>
this listview template which uses div looks like this
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1" >
<LayoutTemplate>
<div runat="server" id="lstProducts">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
<ItemTemplate>
<div runat="server" style="float:left">
<asp:Image runat="server" Style="width: 100px" enableviewstate="false" ID="ImageButton1" ImageUrl='<%# Eval("ImageUrl", "~/Photos/{0}") %>' />
<br />
<asp:Label ID="PropertyTypeLabel" runat="server" enableviewstate="false" Text='<%# Eval("PropertyType") %>' />
<br />
Bedrooms:
<asp:Label ID="BedroomsLabel" runat="server" enableviewstate="false" Text='<%# Eval("Bedrooms") %>' />
<br />
Town:
<asp:Label ID="TownLabel" runat="server" enableviewstate="false" Text='<%# Eval("Town") %>' />
<br />
Lat:
<asp:Label ID="LatLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lat") %>' />
<br />
Lon:
<asp:Label ID="LonLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lon") %>' />
<br />
Price:<asp:Label ID="PriceLabel" runat="server" enableviewstate="false" Text='<%# Eval("Price", "£{0}") %>' />
</div>
</ItemTemplate>
</asp:ListView>
firefox: takes > 2 minutes seconds to render and refreshes/wraps take 40 seconds as page is resized. uses 500mb of memory
IE 8: takes 50 seconds to render and takes 20 seconds to wrap as page is resized. uses 600mb of memory.
so it looks like firefox handles rendering thousands of divs much worse than IE. and on both browsers thousands of spans render faster than divs.

Related

Use different data forms inside default grid view in asp.net

I have the above grid view where I am using the default one provided by Visual Studio. What I am doing is, via the server properties dragging the table and the VS creates the above for me.
However, I want my category 1 and category 2 and category 3 be dropdown lists.
Is there any way to change the default behavior of the grid view?
Use Template Field in the source code inside the grid.
It will look like
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField HeaderText="id" DataField="id" />
<asp:BoundField HeaderText="Name" DataField="name" />
<asp:TemplateField HeaderText = "category1">
<ItemTemplate>
<asp:Label ID="lblcategory1" runat="server" Text='<%# Eval("category1") %>' Visible = "false" />
<asp:DropDownList ID="ddlcategory1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and so on.

Anchor 'a' tag's dynamically "href" link is not working right

I am having problem while clicking on the image wrapped in an Anchor tag. The link is not appearing in the proper order and it shows server error following is my code snippet.
have a look at this, am I doing something wrong
<asp:Repeater ID="repeater1" DataSourceID="datasource1" runat="server" EnableViewState="False">
<ItemTemplate>
<div id="ads">
<a href='<%# Eval("Link") %>' target="_blank">
<asp:Image runat="server" Width="228" Height="189" ToolTip='<%# Eval("Description") %>' ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Image")) %>' />
</a>
</div>
</ItemTemplate>
</asp:Repeater>
if the Link is www.example.com then when I click on the image I get the following url along with localhost/www.example.com appended and it show a server error there.
so why not it navigates to this URL alone i have also used resolveclienturl method too.
kindly help me to solve this problem.

HTML markup renders not as expected

Two ASP.NET Web form pages:
Page1:
Type: Normal asp.net page, no containers or database binding controls
Rendered as: Content Content
Source (as shown in browser tool): <p>Content Content</p>
(Life is happy)
Page2:
Type: Database content, using DetailsView Control
Rendered as: Content Content
Source (as shown in browser tool): <p>Content Content</p>
I'm gonna be mad why does that happen! I want the to be a blank space!
Is that DetailsView charm or what!!
Appendix:
Page2 markup
<ItemTemplate>
<%--Title--%>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>'></asp:Label>
<br />
<%--Date--%>
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("date") %>'></asp:Label>
<br />
<%--Content--%>
<p>
<asp:Literal ID="lblContent" runat="server" Text='<%# Bind("content") %>' />
</p>
</ItemTemplate>
Note that I tried the asp:Label and asp:Literal
Not sure why you would need two-way databinding on a label, so I would probably go back to using something like the following:
<%--Content--%>
<p>
<asp:Literal ID="lblContent" runat="server" Text='<%# System.Web.HttpUtility.HtmlEncode((string)Eval("content")) %>' />
</p>

GridView Centering Issues

How can I center the text of the rows of an <asp:GridView /> that gets populated at run-time?
I have tried RowStyle-HorizontalAlign="Center" and similar things that I have found in this site to no avail.
Similarly, I cannot center a GridView inside a div—that is, <div><asp:GridView /></div>—to save my life.
Am I using a bunch of deprecated functions or what? Also, Chrome is my default browser.
I am aware that a thousand questions in the gist of mine have been asked before, but all that I have tried are either years old or are not working.
Thanks in advance!
Are you using bound columns or autogenerated? If you're binding them in your markup, something like this should work fine (this is an actual example from something of mine):
<asp:TemplateField HeaderText="External Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:TextBox ID="txtExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewExternalId" runat="server" Width="100%" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Ajax:ModalPopup js exception, BackgroundCssClass is null

I use a modal popup extender, i followed all the instructions on the toolkit sample page, except that i didn't set the property BackgroundCssClass.
this is what happens:
Is there a way I can get rude of it without setting the cssclass prop?
I don't need any styles.
If the answer is NO then please show me an example how to set it with a cssclass (even dummy).
Thanks in advance.
Here is the code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<div style="size: 100%; vertical-align: middle">
<asp:LinkButton ID="lnkUpload" Text="Upload" ToolTip="Upload new file" runat="server" OnClick="lnkUpload_Click" />
<cc1:ModalPopupExtender ID="lnkUpload_ModalPopupExtender" runat="server" Drag="true" PopupDragHandleControlID="pnlUploadTitle" DynamicServicePath="" PopupControlID="pnlUpload" Enabled="True" TargetControlID="lnkUpload" CancelControlID="btnCancel" />
</div>
<asp:Panel ID="pnlUploadTitle" runat="server" Visible="false">
<center>
Upload file
</center>
</asp:Panel>
<asp:Panel ID="pnlUpload" runat="server" Visible="false">
<center>
<br />
<asp:FileUpload ID="upFiles" runat="server" /><br />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
</center>
</asp:Panel>
</div>
</form>
You can set the ModalPopupExtender's backgroundCssClass within the actual HTML markup.
Example from the asp.net modal popup page:
<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
TargetControlID="LinkButton1"
PopupControlID="Panel1"
**BackgroundCssClass="modalBackground"**
DropShadow="true"
OkControlID="OkButton"
OnOkScript="onOk()"
CancelControlID="CancelButton"
PopupDragHandleControlID="Panel3" />
I spent ages looking up a solution for the similar problem
Set your PopUpControlId to be the ClientID of the control.
It solved the problem for me.
Also read more on: Codeplex
Ha-ha, I remember more then 2 years ago in AJAX beta not setting the BackgroundCssClass property caused modal popup not to be really modal, but just popup. I remember setting a style class solved the problem. I haven't used AJAX for a long time, it's funny if similar problems still persist.
Anyway, create stylesheet class inside your ASPX page or in CSS file referenced form it and set the property value to it. Maybe, this will also help.