Solved

Best Practices for rendering asp.net web controls

Posted on 2012-03-15
2
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Many of the most common information processing tasks require sorting data sets.  For example, you may want to find the largest or smallest value in a collection.  Or you may want to order the data set in numeric or alphabetical order. …
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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