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

ASP.Net 2.0 - how to add custom style into page header in code in

5 views
Skip to first unread message

sergeypoberezovskiy

unread,
Apr 30, 2007, 10:15:23 PM4/30/07
to
Hi,

What is the "right" way to create a css rule similar to the following in a page header:
<style>
.myRule{text-align:right;padding-right:10px;}
</style>

I know that you can add simple styles as follows:
this.Page.Header.StyleSheet.CreateStyleRule(style, this.Page,
".mySimpleRule");
but then I am not sure how to set text-align, padding or similar styles to a
System.Web.UI.WebControls.Style object

I am trying to avoid putting literal into my header and altering its content.

Any help is appreciated.

Alexey Smirnov

unread,
May 1, 2007, 7:17:42 AM5/1/07
to


private class MyStyle : Style
{
protected override void FillStyleAttributes(CssStyleCollection
attributes, IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
attributes[HtmlTextWriterStyle.TextAlign] = "right";
attributes[HtmlTextWriterStyle.PaddingRight] = "10px";
}
}

this.Page.Header.StyleSheet.CreateStyleRule(new MyStyle(), this.Page,
".myRule");

Sergey Poberezovskiy

unread,
May 1, 2007, 9:31:01 PM5/1/07
to
Thanks - simple and elegant

"Alexey Smirnov" wrote:

> On May 1, 4:15 am, Sergey Poberezovskiy wrote:
> > Hi,
> >
> > What is the "right" way to create a css rule similar to the following in a page header:

> > <style>


> > .myRule{text-align:right;padding-right:10px;}

> > </style>

0 new messages