This article demonstrates how to add css links programmatically in asp.net page using Javascript. Create a link element and appends it as a child to the<Head> tag section. You can use this technique to append style sheet and change the appearance of the page on client side.
Here's an example
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function addCSS() {
var _link = document.createElement('link');
_link.type = 'text/css';
_link.rel = 'stylesheet';
_link.href = 'aamirhasan.css';
document.getElementsByTagName("head")[0].appendChild(_link);
}
window.onload = function () { addCSS(); };
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<h1>
Welcome to aspxtutorial.com
</h1>
<p>
Author:Aamir Hasan
</p>
<a href="http://www.aspxtutorial.com">.NET Articles</a>
</div>
</form>
</body>
</html>
Download
Addcss.zip (996.00 bytes)
See live demo