Solved

Best Practices for rendering asp.net web controls

Posted on 2012-03-15
2
511 Views
Last Modified: 2012-03-15
There are many ways to render controls on an asp.net web page. I would like some feedback on best practices for rendering controls on an asp.net web page based on a data source.

Which way is faster for page load time?
Which way consumes less resources on the server?

For example:
I can programmatically add HyperLink Controls to my page in the following way:
        Dim li As List(Of stcFileInfo) = objDirectorySearcher.GetFilesInDirectory(modAppConfig.PreOrderDirectory, "*.pdf")

        For i As Integer = 0 To li.Count
            Dim h As New HyperLink
            h.ID = "hlnk" & i
            h.CssClass = "SomeClass"
            h.Text = li.Item(i).FullName
            h.ToolTip = li.Item(i).FileName
            h.NavigateUrl = "http://someurl.com"
            h.Target = "_blank"
            pnlPreOrders.Controls.Add(h)
        Next

Open in new window


Or I can Bind a Repeater Control to that list like this:
        rptPreOrders.DataSource = li
        rptPreOrders.DataBind()

Open in new window

            <asp:Repeater ID="rptPreOrders" runat="server">
                <ItemTemplate>
                    <asp:HyperLink ID="hlnk" runat="server" Text='<%# GetTitleCase((Container.DataItem.FileName).Replace((Container.DataItem.Extension),"")) %>'
                        NavigateUrl='<%# GetPartnerAccessURL() & "/" & GetVirtualDirectory() & "/" & Container.DataItem.DirectoryName & "/" & Container.DataItem.FileName %>' Target="_blank" CssClass="applicationlinks"></asp:HyperLink>
                </ItemTemplate>
            </asp:Repeater>

Open in new window

0
Comment
Question by:jsmithr
2 Comments
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 37724891
0
 

Author Closing Comment

by:jsmithr
ID: 37724917
Nice. Just what I was looking for. My mentor said something similar: "Really what matters is readability and code maintenance."

Just double checking, though.
I am interested in learning more about Output Caching, as mentioned in the article via the link you posted.

Thanks again!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The CRUD Functions CRUD, meaning "Create, Read, Update, Delete (http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)" is a common term to data base developers.  It describes the essential functions of data base table maintenance.  This art…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now