473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Style class doesn't support margin or padding css properties

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
3 4112
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
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
Hi Alexey

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

Cheers
Andrew
May 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Herbert | last post by:
I'm still relativey new to stylesheets, so I'm hoping that the way I'm going about things can be seriously improved upon, i.e . I just haven't undersood something obvious about the 'cascading'...
6
by: Haines Brown | last post by:
I find that when I use list-style-image with galeon or mozilla, padding is inserted between the symbol image and the following list text, while under IE 5.0 it seems to be inserted before the image...
5
by: BenOne© | last post by:
Hi all, If I want to have many divs with different padding, border, and colour properties, should I just set those styles in line, ie: <DIV style"..."> </DIV> or should I define all the divs...
1
by: X | last post by:
I cannot figure this one out. I would like to traverse through and elements styles (not class) and get a list of all properties using javascript property names and css property names along with the...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
5
by: Lee | last post by:
I'm a newbie to CSS and I'm wondering if there is a way to implement inheritance in a way similar to C++/Java? ie: if I have a class: div.parent { padding: 0px; margin: 0px } and I want...
8
by: Amit | last post by:
I have a master page and a content page but the stylesheet isnt getting applied like how it looks in visual studio design view. The master page is defined like this: <%@ Master Language="VB"...
4
by: Duncan Jones | last post by:
I'm almost certain there is no easy answer to this question, but I'd thought I'd just check.... *Ignoring* for a second why I want to do this, is there any way to specify that an element in a...
5
by: Nathan Sokalski | last post by:
I have css that would normally be placed in style tags in the header of the Master page that I want to add programmatically for a specific Web Content Form (the *.aspx page). How do I do this for a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.