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.W ebControls.Styl e
{
private System.Web.UI.C ssStyleCollecti on currstyles;
public CustomStyle(Sys tem.Web.UI.CssS tyleCollection custom) {
this.currstyles = custom; }
public CustomStyle(str ing cssvalue)
{
System.Web.UI.C ssStyleCollecti on tempstyle = new
System.Web.UI.W ebControls.WebC ontrol(System.W eb.UI.HtmlTextW riterTag.Unknow n).Style;
tempstyle.Clear ();
tempstyle.Value = cssvalue;
this.currstyles = tempstyle;
}
protected override void
FillStyleAttrib utes(System.Web .UI.CssStyleCol lection
attributes,Syst em.Web.UI.IUrlR esolutionServic e urlResolver)
{
base.FillStyleA ttributes(attri butes, 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.Sty leSheet.CreateS tyleRule(new CustomStyle("fo nt-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_Cr eateStyleRule_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,
<styletags, 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
nj********@hotm ail.com http://www.nathansokalski.com/
"Michelle Sollicito eBarster" <mi************ ****@gmail.comw rote in
message
news:a5******** *************** ***********@v56 g2000hsf.google groups.com...
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:visite d,a:hover,a:act ive{font...
.ebartext{font-family:<%=fontf amily%>;...
.price{font-family:<%=fontf amily%>;fon...
.textfont{font-family:<%=fontf amily%>;...
.{font-family:arial,sa ns-serif;font-si...
table{backgroun d-color:transpare nt;}
.ebaylogo{posit ion:absolute;z-index:40...
.ebarlogo{posit ion:absolute;z-index:40...
.ebarlogotext{f ont-family:arial,sa ns-s...
.ebarcontainer{ position:absolu te;left:...
.clipdiv{positi on:absolute;lef t: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.QuerySt ring["fontfamily "];
Can anyone help?