ASP.NET - Loading a css file in c# - Asked By Daniel on 11-Feb-13 04:05 AM

Hi I am trying to load a css file in c# code but it is not working.Please can someone help:

This is my code :
I have a css file called Style.css and below is the code in the file:

.vtabs { border-right: 1px solid #DDDDDD; display: block; float: left; min-height: 300px; padding: 10px 0; width: 190px; background-color:Black;}


    <form id="form1" runat="server">
       <asp:Literal ID="OrderInfoTab" runat="server"></asp:Literal>

 protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            string str = string.Format("<link rel=\"stylesheet\" href=\"{0}\" type=\"\">", HelperFunctions.GetAbsolutePath(this.Page, "css/Stylecart.css"));
            OrderInfoTab.Text = str;

            string TabHeader = string.Empty;
            string TabDescription = string.Empty;
            TabHeader += "<div class=\"vtabs\">";

            TabHeader += string.Format("<a class=\"selected\">{0}</a>", Resources.Language.OrderDetails);

            TabHeader += "</div>";
Danasegarane Arunachalam replied to Daniel on 11-Feb-13 06:12 AM
Did you see the view source of the file?

Does it printed the text?

And also the <asp:Literal ID="OrderInfoTab" runat="server"></asp:Literal> should be moved to head tag.
Daniel replied to Danasegarane Arunachalam on 11-Feb-13 11:07 AM
I am using a ContentPlaceHolder1 means there is no head there it is used in masterpage...what do you mean by
view source
Danasegarane Arunachalam replied to Daniel on 13-Feb-13 03:16 AM
Try this code in the content place holder and try

HtmlGenericControl si = new HtmlGenericControl();
si.TagName = "link";
    si.Attributes.Add("type", "text/css");
    si.Attributes.Add("href", "css/Stylecart.css");
    si.Attributes.Add("rel", "stylesheet");