Select CSS stylesheet from C#

  • Thread starter Thread starter davidfahy
  • Start date Start date
D

davidfahy

Hi all,
I have written a registration aspx page that I want to "brand"
based on a query string parameter passed to me on a redirect. Basically
if the Service param in the query string is A I want to apply a
stylesheet but if it is B I want to apply a different stylesheet. Is it
possible to select a stylesheet from the Page_Load method in the c#
behind the aspx? Or is there another way to accomplish this?

Thanks in advance
 
you can use skins in ASP.NET 2.0...

Skins are exactly like that, you choose your skin file (it's a CSS file) to
use where in the code you want...

googleit 4 more information under asp.net 2.0 and skins
 
Just add a runat attribute to your traditional link tag. ID attribute has to
be present, and tag has to be properly closed (not like HTML).<head>
<link id="MyStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>Then in your Page_Load, simply add a "href" attribute as below:Sub
Page_Load(Sender As Object, E As EventArgs)
If Not (IsPostBack)
MyStyleSheet.Attributes.Add("href","/css/flostyle.css")
End If
End SubHope this helps
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


<[email protected]> escreveu na mensagem
I'm afraid I can't use 2.0. Is this not possible in 1.1?
 
I tried this but when i try to build I get and error : The type or
namespace name 'MyStyleSheet' could not be found (are you missing a
using directive or an assembly reference?) at the line
MyStyleSheet.Attributes.Add("href","/mysheet.css")
 
no...

check the link:

http://www.codeproject.com/aspnet/setcssfilelink.asp

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


<[email protected]> escreveu na mensagem
I tried this but when i try to build I get and error : The type or
namespace name 'MyStyleSheet' could not be found (are you missing a
using directive or an assembly reference?) at the line
MyStyleSheet.Attributes.Add("href","/mysheet.css")
 
As the object is outside the form, it won't be declared automatically in
the code behind. You have to declare it specifically:

Protected MyStyleSheet as HtmlGenericControl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top