In ASP.NET you will need to do this from within one of the Page events, such
as Load. Here is a class I wrote (with some help from the internet and these
newsgroups):
public class CustomStyle : System.Web.UI.WebControls.Style
{
private System.Web.UI.CssStyleCollection currstyles;
public CustomStyle(System.Web.UI.CssStyleCollection custom) {
this.currstyles = custom; }
public CustomStyle(string cssvalue)
{
System.Web.UI.CssStyleCollection tempstyle = new
System.Web.UI.WebControls.WebControl(System.Web.UI.HtmlTextWriterTag.Unknown).Style;
tempstyle.Clear();
tempstyle.Value = cssvalue;
this.currstyles = tempstyle;
}
protected override void
FillStyleAttributes(System.Web.UI.CssStyleCollection
attributes,System.Web.UI.IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
foreach (string currkey in this.currstyles.Keys) { attributes[currkey] =
this.currstyles[currkey]; }
}
}
In your Page's Load event use a statement similar to the following:
this.Header.StyleSheet.CreateStyleRule(new CustomStyle("font-size:12px;"),
null, ".style1");
You will notice that this statement includes two key parts, the
CreateStyleRule method, which you can see details about at:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref13/html/M_System_Web_UI_IStyleSheet_CreateStyleRule_3_9de1b1b6.htm
For the CreateStyleRule method you will be supplying three parameters, the
Style object returned by a new CustomStyle, null, and a String specifying
the CSS selector.
And the CustomStyle constructor. Although the CustomStyle class has two
constructors, the only one I ever use is the second one, which simply takes
a String of CSS declarations, just as you would enter them in a *.css file,
<style> tags, or HTML style attribute.
It took me a while and a lot of help to figure all this out (I actually got
the original CustomStyle class online, but I had to modify it to include the
second constructor), and I have been doing ASP.NET for a couple years now,
so don't feel bad about not knowing what to do. Hopefully everything I have
supplied will be enough to fix your problem. Good Luck!
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/
"Michelle Sollicito eBarster" <(E-Mail Removed)> wrote in
message
news:a5a39f71-fbb3-4d7e-b907-(E-Mail Removed)...
> Ok I know a lot of asp but not a lot of asp.net and C# so please bear
> with me. I need some help converting..
>
> In my asp project I have some styles in my head tag that change
> according to a parameter passed in in the query string - fontfamily
> is the variable that I store the value of the parameter in within my
> asp code, and then I place that into the styles see below..
>
> <style type="text/css">
> a:link,a:visited,a:hover,a:active{font...
> .ebartext{font-family:<%=fontfamily%>;...
> .price{font-family:<%=fontfamily%>;fon...
> .textfont{font-family:<%=fontfamily%>;...
> .{font-family:arial,sans-serif;font-si...
> table{background-color:transparent;}
> .ebaylogo{position:absolute;z-index:40...
> .ebarlogo{position:absolute;z-index:40...
> .ebarlogotext{font-family:arial,sans-s...
> .ebarcontainer{position:absolute;left:...
> .clipdiv{position:absolute;left:0px;to...
> </style>
>
> I am not sure how to change my stylesheet from within c# and replace
> it with a value passed in as a parameter.
>
> I have gotten the value into the string variable fontfamily, but not
> sure how to place that within the style??
>
> //in my c# code default.aspx.cs I get the parameter passed in fine..
> string fontfamily = "" + Request.QueryString["fontfamily"];
>
> Can anyone help?