?
Solved

Best Practices for rendering asp.net web controls

Posted on 2012-03-15
2
Medium Priority
?
561 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 41

Accepted Solution

by:
Kyle Abrahams earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 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