473,386 Members | 1,785 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,386 software developers and data experts.

Programmatically adding a css style to a web content form

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 Web Content Form? I cannot
use style tags in a Web Content Form, and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jun 27 '08 #1
5 3701
Hello Nathan
>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 Web Content Form? I cannot
use style tags in a Web Content Form, and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
You can Access within your contentpage to the masterpage and throught the
property ".Master"
also to the .Header.

Add there a HtmlGenericControl("style"), or make an Include with an "link"
Tag there.

Look further:

-
http://translate.google.ch/translate...hl=de&ie=UTF-8
(English Translation)

-
http://www.aspnetzone.de/blogs/peter...direktive.aspx
(Original)

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

Jun 27 '08 #2
... and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.

The "Style" property of a web server control is actually a collection
not a single object (really ought to be named "Styles"). So you use
the Add method. CssStyleCollections are actually a list of key/value
pairs where the key is the attribute and the value the value. For
example:

Suppose you have a label control where you want to set the styles
programmatically:

Label1.Style.Add("Color", "Blue");
Label1.Style.Add("font-size", "2em");

will make the text quite large and blue.

HTH

Jun 27 '08 #3
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebControls.Style object, which does not have an Add
method. You seem to have the Style object confused with the
CssStyleCollection object. These two object can be easy to confuse because
the Style property is not an instance of the Style class. Any other
suggestions?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Stan" <go****@philphall.me.ukwrote in message
news:fd**********************************@b1g2000h sg.googlegroups.com...
>... and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.


The "Style" property of a web server control is actually a collection
not a single object (really ought to be named "Styles"). So you use
the Add method. CssStyleCollections are actually a list of key/value
pairs where the key is the attribute and the value the value. For
example:

Suppose you have a label control where you want to set the styles
programmatically:

Label1.Style.Add("Color", "Blue");
Label1.Style.Add("font-size", "2em");

will make the text quite large and blue.

HTH

Jun 27 '08 #4
On May 9, 1:06*am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebControls.Style object, which does not have an Add
method. You seem to have the Style object confused with the
CssStyleCollection object. These two object can be easy to confuse because
the Style property is not an instance of the Style class. Any other
suggestions?
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"Stan" <goo...@philphall.me.ukwrote in message

news:fd**********************************@b1g2000h sg.googlegroups.com...
... *and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
The "Style" property of a web server control is actually a collection
not a single object (really ought to be named "Styles"). So you use
the Add method. CssStyleCollections are actually a list of key/value
pairs where the key is the attribute and the value the value. For
example:
Suppose you have a label control where you want to set the styles
programmatically:
* * * *Label1.Style.Add("Color", "Blue");
* * * *Label1.Style.Add("font-size", "2em");
will make the text quite large and blue.
HTH- Hide quoted text -

- Show quoted text -
Ok, I misread your post slightly. Can I take it then that you are
trying encapsulate a set of css styles in an instance of
System.Web.UI.WebControl.Style class so it can be applied to any
control without having to set the properties for each control
individually? i.e. you are trying to emulate the way css "class"
attributes work without having to access the <styletags.

I have tested the following which works OK
(note that System.Web.UI.WebControl namespace is within scope)

Style s = new Style();
s.Font.Size = FontUnit.Parse("2em");
s.ForeColor = System.Drawing.Color.Blue;
Label1.ControlStyle.CopyFrom(s);

Is that anything like what you are trying to do?

Note also that the Style object does not encapsulate all possible css
styles, e.g. it doesn't handle things like "margin" or "padding"
However the Style object does have a CssClass property that can be
used in the same way as those illustrated above except that the
definition of the css class has to reside in markup in the usual way.

Is there any reason why you can't use themes for all this, which allow
the selected application of both Skin and CSS style sheets, and can be
applied at page level using the @page directive (including content
pages) and hence at control level with css classes and Skin IDs?

Jun 27 '08 #5
Thank you for that information. I think the basic scenario of my situation
is that I am using Master/Content pages, and the CSS class I want will only
be used in one content page. However, the CSS class will not always be the
same, so it must be generated, so I cannot place it in the HTML or an
external stylesheet like you normally would.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Stan" <go********@philhall.netwrote in message
news:b2**********************************@i76g2000 hsf.googlegroups.com...
On May 9, 1:06 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebControls.Style object, which does not have an
Add
method. You seem to have the Style object confused with the
CssStyleCollection object. These two object can be easy to confuse because
the Style property is not an instance of the Style class. Any other
suggestions?
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"Stan" <goo...@philphall.me.ukwrote in message

news:fd**********************************@b1g2000h sg.googlegroups.com...
... and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
The "Style" property of a web server control is actually a collection
not a single object (really ought to be named "Styles"). So you use
the Add method. CssStyleCollections are actually a list of key/value
pairs where the key is the attribute and the value the value. For
example:
Suppose you have a label control where you want to set the styles
programmatically:
Label1.Style.Add("Color", "Blue");
Label1.Style.Add("font-size", "2em");
will make the text quite large and blue.
HTH- Hide quoted text -

- Show quoted text -
Ok, I misread your post slightly. Can I take it then that you are
trying encapsulate a set of css styles in an instance of
System.Web.UI.WebControl.Style class so it can be applied to any
control without having to set the properties for each control
individually? i.e. you are trying to emulate the way css "class"
attributes work without having to access the <styletags.

I have tested the following which works OK
(note that System.Web.UI.WebControl namespace is within scope)

Style s = new Style();
s.Font.Size = FontUnit.Parse("2em");
s.ForeColor = System.Drawing.Color.Blue;
Label1.ControlStyle.CopyFrom(s);

Is that anything like what you are trying to do?

Note also that the Style object does not encapsulate all possible css
styles, e.g. it doesn't handle things like "margin" or "padding"
However the Style object does have a CssClass property that can be
used in the same way as those illustrated above except that the
definition of the css class has to reside in markup in the usual way.

Is there any reason why you can't use themes for all this, which allow
the selected application of both Skin and CSS style sheets, and can be
applied at page level using the @page directive (including content
pages) and hence at control level with css classes and Skin IDs?


Jun 27 '08 #6

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

Similar topics

1
by: Saiyan Vejita | last post by:
I am trying to add some padding to my table; that is, I want to add space between the red outer border and the content within. However, setting the "padding : 30px;" within the TABLE area of my...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
5
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That...
0
by: TB | last post by:
Hi All: I have this page where a rows / cells are programmatically added to to table by pushing a button. The rows contain a textbox and a associated button. What I want to is to be able to...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
9
by: Dhiru1009 | last post by:
Hi guys, I am trying to build a user registration form using PHP and MYSQL but encountring a problem. When I click on submit with empty fields it adds records to database also it doesn't matter...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.