Saturday, March 24, 2012

Setting stylesheets at runtime

I'm developing a vb.net web application. At registration users are able to select which stylesheet they would like for the site, this is stored in the database. How do I set the stylesheet to be used at the time that the page loads.

I know how to get the information from the database, just need an example of how I can change the stylesheet on the flyHi,

just place your <link> tag like you normally would but also add this:

runat="server" id="myDynamicLink"

In your code-behind you just add the line:

protected myDynamicLink ashtmlgenericcontrol.

There you can set the properties in code-behind that you need.
Grz, Kris.
Still not sure exactly how this will work, this is what I have already.

<link href="http://links.10026.com/?link=stylesheets/default.css" type="text/css" rel="stylesheet" /
do you mean like the following.

<link id=myDynamicLink type="text/css" rel="stylesheet" runat="server" /


here is an example using the webconfig, you can change the href property to whatever.
<link id="Stylesheet" runat="server"></link
Dim link As System.Web.UI.HtmlControls.HtmlGenericControl
link = Me.Page.FindControl("Stylesheet")
link.Attributes("rel") = "stylesheet"
link.Attributes("href") = ConfigurationSettings.AppSettings("CSSNAME")
link.Attributes("type") = "text/css"

0 comments:

Post a Comment