Solved

Best Practices for rendering asp.net web controls

Posted on 2012-03-15
2
542 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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