dynamic css file

D

Daves

what would be the easiest way to create a dynamic css file to link to eg

....
<head>
<link type="text/css" rel="Stylesheet" href="lis.aspx" />
</head>
....


this one quite clumsy since it's creating a whole Page class to simply
create dynamical output (text file)?
 
A

alex.sorokoletov

I think you should use handler's files - .ashx
I think, you will find all necessary info in MSDN and, also, at
codeproject.com
 
D

Daves

I've done my Googling and searching also now on Codeproject - can please
someone help me finding articles or at least give me the correct keywords
for Google?
 
V

Vadivel Kumar

My understanding about your problem is, you want to get the CSS
attributes dynamically using a Server call, rather than just placing the
CSS file in the LINK tag.

If it is right, then look at the below code, the code is for an custom
control which placess <style> tag in the page and reads the CSS file and
writes the CSS tags inside the <style> tag.

...

public class CssWriter : WebControl
{
public CssWriter : base (HtmlTextWriterTag.Style)
{}

void Render(HtmlTextWriter writer)
{
TextReader reader
= new FileStream(this.Server.MapPath("cssfile.css" ...

writer.Write(reader.ReadToEnd());
}
}
...
....

As i mentioned before this code reads the CSS file and places the
content into the Writer object, which inturns writes the CSS tags in the
page. Though I mentioned <style> as a the html tag should be used by the
control thru the constructor atlast, the page will result in writing the
Css tags inside the <style> tag.

If you place this control inside the .aspx file

...
<head>
<cc1:CssWriter id="csw1" runat="server"></cc1:CssWriter>
</head>
...

and look at the View Source from browser, you can see the Css tags are
written inside the <style> tag.

This is pretty straightforward way and efficient as well. But, you
should know little bit about Custom Control development in ASP.NET
for implementing this code properly.

Let me know if this doesn't solves your problem.
 

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

Top