Asp.Net Example -Change css file dynamically asp.net

This asp.net example article will Demonstrates you  how to Dynamically set a link to a CSS file in ASP.NET .For Dynamically set a link to a CSS file in ASP.NET follow the below steps.







1-For Dynamically set a link add a runat attribute to your traditional link tag this tag must have its ID attaribute present.



<head>
<link id="MyCSSSheet" rel="stylesheet" type="text/css" runat="server" />
</head>



2-Now in your content page Page_Load event , add  the  "href" attribute of the link tag as below.


   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           MyCSSSheet.Attributes.Add("href","path of Css file");

        }
    }

Tags:

Join Us!