ASP.NET VB:Loading CSS Dynamically

Hi, An ASP.NET question again.The assignment is simple.I have 2 css style sheets that I need to switch back and forth to display some events.I intent to load the pages dynamically switch between the sheets dynamically using radio buttons,so on page load I have code that looks like this: Dim link As New HtmlLink() If rblCSS1.SelectedValue = "ShowCSS1" Then link.Href = "css1.css" link.Attributes.Add("rel", "stylesheet") link.Attributes.Add("type", "text/css") Page.Header.Controls.Add(link) Else link.Href = "css2.css" link.Attributes.Add("rel", "stylesheet") link.Attributes.Add("type", "text/css") Page.Header.Controls.Add(link) End If Apparently this is supposed to add the links to the css dynamically but thats not happening.Anyone who knows why this is the case? And thanks to all who inboxed me and helped when I posted the last question. Edwin Wambua

try using themes and state your css in different folders pass it using C# *public partial class _Default : System.Web.UI.Page* { protected void Page_Load(object sender, EventArgs e) { } protected void SwitchStylesheets(object sender, EventArgs e) { if (radioDark.Checked) stylesheet.Href = "A.css"; if (radioLight.Checked) stylesheet.Href = "B.css"; } }

Thanks. Sounds very simple but I can't get it to work.I got some additional info here <http://msdn.microsoft.com/en-us/library/75ydzzy6%28VS.80%29.aspx> It doesnt recognise the stylesheet.Href I suspect there's a namespace I havent included apart from *System.Web.UI.Page* and *System.Web.UI.HtmlControls*or is it referenced differently in VS2010,which I'm using?
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Try add the following name space System.Web.UI.HtmlControls.HtmlHead HtmlHead header = this.Page.Header as HtmlHead; If rblCSS1.SelectedValue = "ShowCSS1" Then { HtmlLink link = new HtmlLink(); link.Attributes.Add("href", "~/DIRECTORY_PATH/css1.css"); link.Attributes.Add("media", "screen"); link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("type", "text/css"); header.Controls.Add(link); } On 28 January 2011 18:23, Edwin Wambua <eddwak@gmail.com> wrote:
Thanks. Sounds very simple but I can't get it to work.I got some additional info here <http://msdn.microsoft.com/en-us/library/75ydzzy6%28VS.80%29.aspx> It doesnt recognise the stylesheet.Href I suspect there's a namespace I havent included apart from *System.Web.UI.Page* and * System.Web.UI.HtmlControls* or is it referenced differently in VS2010,which I'm using?
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
participants (3)
-
Benjamin
-
Edwin Wambua
-
kenoti maembe