Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

linking cascading style sheet

  Asked By: Francisca    Date: Jun 03    Category: Asp.net    Views: 1047
  

I am trying to link a css to my project, but I am having some problems. I
created a styles.ascx file which contains this code:


<% Control Language="vb"%>

<%

Response.Write("<link rel='stylesheet' type='text/css'
href='styles.css'></link>")

%>

Then I did this to the page I wanted to use the css in:

<%Register TagPrefix="stylesheet" TagName="Style" Src="Styles.ascx"%>

<head>

<stylesheet:Style Runat="server"></stylesheet:style>

</head>

the pages run but it doesn't apply the style sheet. Anyone know any tricks to
making this work.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Phoebe Brown     Answered On: Jun 03

First, why are you doing this with a User Control?
It would be much easier to access the StyleSheet
you wanted  to use from a database. Let's say you
had a list of StyleSheets in a database table and
you wanted to change the style  you used on your
site every week.

You could place a LiteralControl in the Head section
of your aspx file  and set it's text in the codebehind
file:
Literal1.Text = "<link rel='stylesheet' type='text/css'
href='styles.css'></link>";

This information could be dynamically provided
from either a database or and XML file. You could
have a form which allowed you to change the
StyleSheet you wanted to use when your page  loaded.

 
Didn't find what you were looking for? Find more on linking cascading style sheet Or get search suggestion and latest updates.




Tagged: