I am trying to find the best practice for generating and outputting html which would require a database query first to obtain the info. Currently in the aspx page I have a div with runat server:
<div runat='server' id='leaflet'></div>
Now just as a start to do a bit of testing I have a method that runs on page_load that basically does:
private void BuildLeaflet(string qnid) { //gets leaflet details QueryLeafletDetails(); //return concatenated content string leaflet.InnerHtml '<h1>' + dr['LSC Descriptor'] + '</h1>'; }
In the real solution the return is a concatenation of about 10 fields some very long as they are content.
I don’t by any means think this is the best solution, but what is? A StringBuilder? Can I Write Each Part in turn to the site avoiding the concatenation in the method? Is the server div even best?
Edit: Forgot to put some of my content sections have simple (limited) html in them already such as paragraph, list… This allows me to easily produce documents for web and printing, I just use different stylesheets.
I would use
<asp:Literal runat='server' enableViewState='false' id='leaflet' />. This doesn’t generate any tags on the page, and doesn’t stuff all the text in the ViewState.And yes, use StringBuilder if you need to concatenate many long strings. This will be way more memory efficient.
The other solution would be to see if you can make some fixed markup on the page and put the contents of each DB field in it’s own control (
<asp:Literal />?).