I'm struggling with changing the CSS href in the code-behind of my .ASPX page. I've tried various methods but haven't found a solution that works as intended.
HTML Markup:
<link id="linkCSS" runat="server" href='/css/1.css' rel="stylesheet" type="text/css" />
This is what I have attempted in Code behind:
If (mobile)
{
HtmlLink link = (HtmlLink)this.FindControl(linkCSS.UniqueID);
link.Href = "/css/2.css";
}
Unfortunately, I am encountering the following exception:
Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.HtmlControls.HtmlLink'.
Any suggestions or ideas would be greatly appreciated. Thank you.