Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2013, 01:36 AM
Authorized User
 
Join Date: Nov 2012
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default Most efficient code

I am fairly new to asp.net and am not sure which is the most efficient way to write certain code. I am showing two examples, the first which is shorter too write, but when the browser produces the html code which is best? I am combining Asp.Net with Bootstrap BTW. Thank you

code
<div class="container two">

<h1>Crete</h1>
<h4>Beautiful beaches,great accomodation, fabulous food...A great place for a holiday with your family and friends.</h4>

<ul class="thumbnails three">
<li>
<asp:ListView ID="ListView1" runat="server" DataSourceID="EntityDataSource1">
<ItemTemplate>

<asp:HyperLink ID="HyperLink1"
ImageUrl='<%# Eval("Photo") %>'
NavigateUrl='<%# Eval("Link") %>'
ToolTip='<%# Eval("Description") %>'
Target="_blank"
runat="server"></asp:HyperLink>

</ItemTemplate>
</asp:ListView>
</li>
</ul>

<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=PictureEntities1"
DefaultContainerName="PictureEntities1" EnableFlattening="False"
EntitySetName="ImageWalls" Select="it.[Link], it.[Description], it.[Photo]">
</asp:EntityDataSource>

</div> <%--End Container Two--%>
/code


code
<li>
<a href="Tavernas.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/1b.jpg" alt="" />
</a>
</li>

<li>
<a href="Tavernas.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/2b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/3b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/4b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/5b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/6b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.googleartproject.com/collection/acropolis-museum/" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/7b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.googleartproject.com/collection/acropolis-museum/" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/8b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.heraklion.gr/en/city/archeological-museum/archeological-museum.html" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/9b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.botanical-park.com/" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/10b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.chania-oldtown-walks.com/" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/11b.jpg" alt="" />
</a>
</li>

<li>
<a href="#" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/12b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://en.wikipedia.org/wiki/Georgioupoli" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/13b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/14b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.cretanvillas.co.uk" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/15b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.cretanvillas.co.uk" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/16b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/17b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://www.samariagorge.eu/" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/18b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://en.wikipedia.org/wiki/Aptera,_Greece" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/19b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/20b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/21b.jpg" alt="" />
</a>
</li>

<li>
<a href="#" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/22b.jpg" alt="" />
</a>
</li>

<li>
<a href="http://limnoupolis.gr" target="_blank" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/23b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/24b.jpg" alt="" />
</a>
</li>

<li>
<a href="Beach.aspx" class="thumbnail">
<img data-src="holder.js/200x200" src="CubePhotos/25b.jpg" alt="" />
</a>
</li>

/code
 
Old May 6th, 2013, 06:34 AM
Registered User
 
Join Date: May 2013
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default most effecient code

Given that I don't know your domain, my suggestion would try to page it and example 1000 rows at a time because I cannot see user seeing all 2 million rows at one time

Else get only the records just required of the user, for the user, by the user
The Following User Says Thank You to barbarahambly For This Useful Post:
tommein (May 6th, 2013)
 
Old May 6th, 2013, 07:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're really comparing apples and oranges.

Your first code snippet is server side code that goes out to the database using an EntityDataSource, gets the request picture information and then builds up the HTML that is eventually sent to the client.

The second example is already plain HTML and as such can be sent to the client directly.

Considering the fact that the server side code queries the database to get data, it will always be slower. However, if you need to get dynamic data, then you really don't have a choice. If all you need is static HTML, now and in the future, the second example might be enough.

So, this isn't about speed, but about functionality. If you don't need data from a database, use the second example.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
tommein (May 6th, 2013)
 
Old May 6th, 2013, 08:47 AM
Authorized User
 
Join Date: Nov 2012
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default Effecient Code

Thank you Imar
I did understand the different workings, I did not know which method would produce the quickest loading of the web-site.

Thank you again for your time
 
Old May 13th, 2013, 02:31 AM
Authorized User
 
Join Date: Nov 2012
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default Database required

The first code block references a small table in a database.
The fields were:-

code
ThumbID (PK, int not null)
Link (nvarchar(max), not null)
Description (nvarchar(100), not null)
Photo (nvarchar(100), not null)
/code

I used the wizard in Visual Studio to set up a link with Entity Framework.

Hope this helps

Tom
 
Old May 22nd, 2013, 03:25 AM
Authorized User
 
Join Date: Nov 2012
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default Entity databases

Hi hocnishwhite
If you follow chapter 14 in Imars book Beginning asp.net, this is a good description of how to set up E.F. database with the format shown, then the code block that is right at the top of the page goes into your aspx page.
Shown below is one row from the database. The number is the 'ID', the next section is the 'Link' and the third is the 'link to the image'
code
'7' 'http://www.googleartproject.com/collection/acropolis-museum/' 'The Acropolis, a day trip to Athens' 'CubePhotos/7b.jpg'
/code

I used Bootstrap to format the page.
You can see the result at http://www.tersanas.com/LinkWall.aspx .
Good luck and hope this helps





Similar Threads
Thread Thread Starter Forum Replies Last Post
More Efficient way to get data from a table? kiwidancer Excel VBA 5 September 20th, 2009 06:56 AM
Efficient code for beginners.... stevemcd999 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 February 27th, 2009 06:56 AM
Most efficient overriding technique jcsdeveloper C# 4 December 7th, 2005 04:18 PM
Database search - more efficient way? SoC Classic ASP Basics 4 August 15th, 2004 08:56 PM
Paging Again Still Not Efficient alyeng2000 ASP.NET 1.0 and 1.1 Basics 0 March 4th, 2004 08:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.