Best Way to Generate HTML And Position Using C#

Posted on 2009-04-26
Last Modified: 2013-11-07
Hello Experts,

I'm looking for a best practice recommendation on how to control the placement of HTML that I am generating server side within PageLoad().

I am looping through a datatable and generating some HTML for every record in the table.  It's a very small about of data (less than 30 rows).  I'm saving the HTML in a StringBuilder and then assigning the HTML to the text value of a label control on my ASP.NET page.  

label.text = sb.ToString();

Is there a better way of accomplishing this?  I'm having an issue where the html on this label isn't displaying immediately when the page loads, unless you click somewhere in the page.  This only happens in IE not Firefox.  I don't know if this issue is related, but I'm looking for a best practice recommendation.

Is there a better option than looping through the data during PageLoad()?
Question by:soapygus
    LVL 9

    Accepted Solution

    LVL 14

    Assisted Solution


    Use HtmlTextWriter class to generate html at runtime. Of course you will use StringBuilder class here but the html code is generated using HtmlTextWriter.
    LVL 9

    Expert Comment

    if you need any help, we are always here to help

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    728 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

    21 Experts available now in Live!

    Get 1:1 Help Now