tags:

views:

31

answers:

2

What would be the best approach to set dynamic content from the database to controls in an aspx page?

My database consists of pages (index.aspx, home.aspx and so on) which consists of controls (DivStart, LabelDescription, and so forth).

The first technique that came to my mind was looping through all the controls in the page, looking for controls that have a certain class, e.g. "Cms_DivStart", and would then set the inner html for that control from the database control called "DivStart". The problem is only runat server controls shows up, and I don't want to make all controls server side.

I could store all the dynamic texts for a page in hidden variables and set it with jQuery when the page has loaded, but that would make the text not show up directly..

Any other ideas would be greatly appreciated.

Thanks /Andreas

A: 

You could use asp:PlaceHolder tags, these don't add any html unless they are utilised.

CodeBadger
A: 

You can write a custom class, I'll call it "CustomPage", that inherits the System.Web.UI.Page class. Then your pages can inherit "CustomPage". In this class, add methods to retrieve data, set custom properties and display your content in the available controls.

Silkster