473,732 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y 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 programmaticall y 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.W ebControls.Styl e object. Can anyone help me? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Jun 27 '08 #1
5 3739
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 programmaticall y 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.Sty le 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 HtmlGenericCont rol("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.W ebControls.Styl e 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. CssStyleCollect ions 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
programmaticall y:

Label1.Style.Ad d("Color", "Blue");
Label1.Style.Ad d("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.WebContr ols.Style object, which does not have an Add
method. You seem to have the Style object confused with the
CssStyleCollect ion 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********@hotm ail.com
http://www.nathansokalski.com/

"Stan" <go****@philpha ll.me.ukwrote in message
news:fd******** *************** ***********@b1g 2000hsg.googleg roups.com...
>... and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI. WebControls.Sty le 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. CssStyleCollect ions 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
programmaticall y:

Label1.Style.Ad d("Color", "Blue");
Label1.Style.Ad d("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...@hot mail.comwrote:
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebContr ols.Style object, which does not have an Add
method. You seem to have the Style object confused with the
CssStyleCollect ion 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...@hotm ail.comhttp://www.nathansokal ski.com/

"Stan" <goo...@philpha ll.me.ukwrote in message

news:fd******** *************** ***********@b1g 2000hsg.googleg roups.com...
... *and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.W ebControls.Styl e 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. CssStyleCollect ions 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
programmaticall y:
* * * *Label1.Style.A dd("Color", "Blue");
* * * *Label1.Style.A dd("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.W ebControl.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.W ebControl namespace is within scope)

Style s = new Style();
s.Font.Size = FontUnit.Parse( "2em");
s.ForeColor = System.Drawing. Color.Blue;
Label1.ControlS tyle.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********@hotm ail.com
http://www.nathansokalski.com/

"Stan" <go********@phi lhall.netwrote in message
news:b2******** *************** ***********@i76 g2000hsf.google groups.com...
On May 9, 1:06 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebContr ols.Style object, which does not have an
Add
method. You seem to have the Style object confused with the
CssStyleCollect ion 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...@hotm ail.comhttp://www.nathansokal ski.com/

"Stan" <goo...@philpha ll.me.ukwrote in message

news:fd******** *************** ***********@b1g 2000hsg.googleg roups.com...
... and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.W ebControls.Styl e 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. CssStyleCollect ions 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
programmaticall y:
Label1.Style.Ad d("Color", "Blue");
Label1.Style.Ad d("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.W ebControl.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.W ebControl namespace is within scope)

Style s = new Style();
s.Font.Size = FontUnit.Parse( "2em");
s.ForeColor = System.Drawing. Color.Blue;
Label1.ControlS tyle.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
15975
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 CSS doesn't seem to be having any affect. Is there a way to add padding to a table via CSS? I can use <table CELLSPACING=>, but it's a rather coarse way of doing
5
6822
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 way is using javascript - does anybody have a sample for this ? Thanks
3
2343
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 page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
5
1548
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 is, a user goes to the web page, which draws the current content out of the db and inserts into a "preview" area as well as the form itself. User makes changes, hits submit button. The page *should* refresh, with the changes saved to the db, and...
0
1181
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 add the content of any textbox to a global variable (and a related session variable) when pushing the associate button. However whenever I push the button(s) apparently the session variable is not
1
2467
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 guy's Javascript "combo box" - http://sandy.mcarthur.org/javascript/select/select.html. It allows my users (when I get some!) to select from a list of preexisting options and also to add a new one by clicking on "add new". Essentially it's a select...
2
15070
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 been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
2
7666
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 PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate the very unlikely contingency that someone's e-mail account is compromised. Challenging with the...
9
6128
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 what information I put it always add records to database when I click on submit. What can I do to make sure user will not be able to add records to database until he enters the right information? I am posting my code for you guys to have a look...
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.