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.

1

2 Answers 2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

i need to change between language

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.