views:

80

answers:

2

Hi all!

I'm having hard time finding a nice and clear solution on how to create a web page that loads it's style attributes from a database f.ex. button back- and forecolor, font size etc.to a Session object and from there would set them on each page to needed controls.

I have a loader in the Global.asax -> Session_Start which loads the values from db to session object called "settings". Next I tried to use Themes and set those attributes on a skin file f.ex. " to make it simple to change all the buttons at one place. But on ASP.NET one can't set attributes like that on server controls.

So there's of course the possibility that on each and every web page I set those styles in the Page_Load method on each web control I have but I don't consider that very robust a, efficient or neat option. So if someone would have any idea on this, how it should be done so that the maintenance and the robustness of the code preserves as good as possible I really would appreciate your help.

Yours,

Arto Kainu

A: 

You need open a dataset or datareader and next associated this to control Attributes.

Button1.Attributes.Add ("font-family", ds.Tables[0].Rows[0]["font"].ToString());
Button1.Attributes.Add ("color", ds.Tables[0].Rows[0]["color].ToString());
pho3nix
A: 

A possibility coud be that, rather than loading all individual styles, you could dynamically add a reference to a style sheet within *Page_Load*:

if (!Page.IsPostBack)
{    
    HtmlGenericControl link = new HtmlGenericControl("LINK");
    link.Attributes.Add("rel","stylesheet");
    link.Attributes.Add("type","text/css");
    link.Attributes.Add("href", Session["styleSheetName"]);
    Controls.Add(link);
}

If need be, you could dynamically create the style sheet with the settings from the database and then create a reference to that newly created style sheet.

CAbbott