By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Style class doesn't support margin or padding css properties

P: n/a
Hi

I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?

// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add

// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");

Many thanks
Andrew
May 30 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 30, 2:49 pm, "J055" <j...@newsgroups.nospamwrote:
Hi

I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?

// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add

// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");

Many thanks
Andrew
class MyStyle : Style
{
protected override void FillStyleAttributes(CssStyleCollection
attributes, IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
attributes[HtmlTextWriterStyle.Margin] = "0 0 0 0";
attributes[HtmlTextWriterStyle.Padding] = "0 0 0 0";
}
}

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

May 30 '07 #2

P: n/a
On May 30, 3:00 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 30, 2:49 pm, "J055" <j...@newsgroups.nospamwrote:


Hi
I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?
// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add
// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");
Many thanks
Andrew

class MyStyle : Style
{
protected override void FillStyleAttributes(CssStyleCollection
attributes, IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
attributes[HtmlTextWriterStyle.Margin] = "0 0 0 0";
attributes[HtmlTextWriterStyle.Padding] = "0 0 0 0";
}
}

this.Page.Header.StyleSheet.CreateStyleRule(new MyStyle(), this.Page,
".myRule");- Hide quoted text -

- Show quoted text -
for Margin-Left rule simply add

attributes[HtmlTextWriterStyle.MarginLeft] = "20px";

May 30 '07 #3

P: n/a
Hi Alexey

Thanks for this. That's exactly what I needed.

Cheers
Andrew
May 30 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.