Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Select CSS stylesheet from C#

0 views
Skip to first unread message

davi...@gmail.com

unread,
Jun 13, 2006, 7:27:29 AM6/13/06
to
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

Bruno Alexandre

unread,
Jun 13, 2006, 7:34:05 AM6/13/06
to
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


--

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


<davi...@gmail.com> escreveu na mensagem
news:1150198049.6...@f6g2000cwb.googlegroups.com...

davi...@gmail.com

unread,
Jun 13, 2006, 7:42:32 AM6/13/06
to
I'm afraid I can't use 2.0. Is this not possible in 1.1?

Bruno Alexandre

unread,
Jun 13, 2006, 8:25:01 AM6/13/06
to
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)


<davi...@gmail.com> escreveu na mensagem
news:1150198952.0...@i40g2000cwc.googlegroups.com...

davi...@gmail.com

unread,
Jun 13, 2006, 9:06:10 AM6/13/06
to
Ok yeah I see what you mean. Thanks a lot for your help.

davi...@gmail.com

unread,
Jun 13, 2006, 9:18:03 AM6/13/06
to
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")

Bruno Alexandre

unread,
Jun 13, 2006, 9:30:26 AM6/13/06
to
no...

check the link:

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

--

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


<davi...@gmail.com> escreveu na mensagem
news:1150204683.0...@f6g2000cwb.googlegroups.com...

Göran Andersson

unread,
Jun 13, 2006, 9:57:20 AM6/13/06
to
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

0 new messages