Solved

Best Practices for rendering asp.net web controls

Posted on 2012-03-15
2
544 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

The Fluent Interface Design Pattern You can use the Fluent Interface (http://en.wikipedia.org/wiki/Fluent_interface) design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that r…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 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