1

How to add CSS link file to ASP.NET page header dynamically using C#?

I need to change between language by changing CSS style file dynamically. Please help me to do this. Thank you in advance.

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
KHALID
  • 143
  • 5
  • 16
  • 2
    I think this has been answered before: http://stackoverflow.com/questions/2943037/adding-stylesheets-programmatically-in-asp-net – Sam Huggill Sep 12 '11 at 06:59

2 Answers2

5

Use HtmlLink class to add css dynamically, this is how:

protected void Page_Init(...)
{
    HtmlLink myHtmlLink = new HtmlLink();
    myHtmlLink.Href = "~/css1.css";
    myHtmlLink.Attributes.Add("rel", "stylesheet");
    myHtmlLink.Attributes.Add("type", "text/css");

    Page.Header.Controls.Add(myHtmlLink);
}
Waqas
  • 6,812
  • 2
  • 33
  • 50
0

i need to change between language

Consider using resx-files if the elements depend on the selected languages.

K232
  • 1,040
  • 14
  • 36