I want to add StyleSheets programmatically in the head section but one of the examples I saw seemed to need to many lines of code to add just one style sheet even though I m
I went a step over, I wanted a method that makes me impossible to add include duplicates, something like ClientScriptManager.RegisterClientScriptInclude()
.
The solution is to give an ID to the control added in the Header section.
if (!String.IsNullOrEmpty(Key))
if (Page.Header.FindControl(Key) != null) return;
HtmlLink link = new HtmlLink();
if (!String.IsNullOrEmpty(Key)) link.ID = Key;
link.Href = StyleUrl;
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(link);
For the complete article I wrote: http://www.idea-r.it/Blog.aspx?Article=49