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

  • Thread starter Sergey Poberezovskiy
  • Start date
S

Sergey Poberezovskiy

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.
 
G

Guest

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.


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");
 
G

Guest

Thanks - simple and elegant

Anon User said:
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.


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");
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top