473,566 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change BgColor of aspx page in code

How do I programatically change the background color of an aspx page in
code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in code?

I am using Visual Studio 2003, building an ASP.NET web application using
VB.NET.

Thanks,,,,, Cliff
Nov 18 '05 #1
7 2749
Jos
Cliff Cavin wrote:
How do I programatically change the background color of an aspx page
in code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in
code?

I am using Visual Studio 2003, building an ASP.NET web application
using VB.NET.

Thanks,,,,, Cliff


Add an id to the body tag of the page like this:
<body id="bodytag" runat="server">
This makes the body tag accessible from your code.

Then, use this code to set the color (for VB):
bodytag.Attribu tes("bgcolor")= "green"
or
bodytag.Attribu tes("bgcolor")= "#ffffff"

--

Jos
Nov 18 '05 #2
Thanks Jos,

But I could not get that to work.
I changed my <Body> tage to be:
<body id="PageBody" runat="server">

But, from with VB it says that PageBody is undeclared.
I suspect that is because the body tag is not within the main
<FORM id="Form1" method="post" runat="server"> tag.

I can not move the body tags to be within the form tag because then
it says "Per the active schema, the element 'FORM' cannot be nested within
'html'.

The search continues,,,,, Cliff
"Jos" <jo************ ***@fastmail.fm > wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl...
Cliff Cavin wrote:
How do I programatically change the background color of an aspx page
in code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in
code?

I am using Visual Studio 2003, building an ASP.NET web application
using VB.NET.

Thanks,,,,, Cliff


Add an id to the body tag of the page like this:
<body id="bodytag" runat="server">
This makes the body tag accessible from your code.

Then, use this code to set the color (for VB):
bodytag.Attribu tes("bgcolor")= "green"
or
bodytag.Attribu tes("bgcolor")= "#ffffff"

--

Jos

Nov 18 '05 #3
Are you using code behind? You'll need to declare the body tag as
HtmlGenericCont rol
"Cliff Cavin" <Cl********@hot mail.com> wrote in message
news:Oh******** ******@TK2MSFTN GP12.phx.gbl...
Thanks Jos,

But I could not get that to work.
I changed my <Body> tage to be:
<body id="PageBody" runat="server">

But, from with VB it says that PageBody is undeclared.
I suspect that is because the body tag is not within the main
<FORM id="Form1" method="post" runat="server"> tag.

I can not move the body tags to be within the form tag because then
it says "Per the active schema, the element 'FORM' cannot be nested within
'html'.

The search continues,,,,, Cliff
"Jos" <jo************ ***@fastmail.fm > wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl...
Cliff Cavin wrote:
How do I programatically change the background color of an aspx page
in code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in
code?

I am using Visual Studio 2003, building an ASP.NET web application
using VB.NET.

Thanks,,,,, Cliff


Add an id to the body tag of the page like this:
<body id="bodytag" runat="server">
This makes the body tag accessible from your code.

Then, use this code to set the color (for VB):
bodytag.Attribu tes("bgcolor")= "green"
or
bodytag.Attribu tes("bgcolor")= "#ffffff"

--

Jos


Nov 18 '05 #4
Yes, I am using code-behind.

How do I declare the body tag as HtmlGenericCont rol ?

Thanks,,,, Cliff

"Showjumper " <sh*******@grkj ashdjkf.com> wrote in message
news:O6******** ******@tk2msftn gp13.phx.gbl...
Are you using code behind? You'll need to declare the body tag as
HtmlGenericCont rol
"Cliff Cavin" <Cl********@hot mail.com> wrote in message
news:Oh******** ******@TK2MSFTN GP12.phx.gbl...
Thanks Jos,

But I could not get that to work.
I changed my <Body> tage to be:
<body id="PageBody" runat="server">

But, from with VB it says that PageBody is undeclared.
I suspect that is because the body tag is not within the main
<FORM id="Form1" method="post" runat="server"> tag.

I can not move the body tags to be within the form tag because then
it says "Per the active schema, the element 'FORM' cannot be nested within 'html'.

The search continues,,,,, Cliff
"Jos" <jo************ ***@fastmail.fm > wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl...
Cliff Cavin wrote:
> How do I programatically change the background color of an aspx page
> in code?
>
> Is there something like Page.BgColor = "#FFFFFF" ?
>
> For that matter, how do I access any of the DOCUMENT properties in
> code?
>
> I am using Visual Studio 2003, building an ASP.NET web application
> using VB.NET.
>
> Thanks,,,,, Cliff

Add an id to the body tag of the page like this:
<body id="bodytag" runat="server">
This makes the body tag accessible from your code.

Then, use this code to set the color (for VB):
bodytag.Attribu tes("bgcolor")= "green"
or
bodytag.Attribu tes("bgcolor")= "#ffffff"

--

Jos



Nov 18 '05 #5
Finally! I got it.

To programatically , using VB Code Behind, change the background color at
Page_Load time, do this:

1) Bring up the HTML for the aspx page.
2) Change the <body> tag to <body id="PageBody" runat="server")
3) Bring up the code behind and place this code in the Page_Load event, or
actuall I guess it could go anywhere:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyBody As New HtmlGenericCont rol
MyBody = Page.FindContro l("PageBody")
MyBody.Attribut es("bgcolor") = "#FF00FF"
End Sub
Note: The Page.FindContro l seems to to be the missing link.
Missing from all VS MSDN Library.
Missing from all newsgroup posts.

If you leave out the line: MyBody = Page.FindContro l("PageBody")
the solution will still compile and run. It just won't change the
background color.

Unfortuately, the documentation that comes with VS is all from the point of
view that you are NOT using code behind. And there *are* a few small
differences between using code behind and not using code behind.

Well, there goes another 8 hours of my life researching something that
should be stupid simple.

I am guessing this same idea could be extended to manipulate any of the
otherwise unreachable DOCUMENT properties from within code (although I have
not had the courage to try yet).

Hope this helps the next guy with the same *simple* question.

Cliff

"Cliff Cavin" <Cl********@hot mail.com> wrote in message
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
How do I programatically change the background color of an aspx page in
code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in code?

I am using Visual Studio 2003, building an ASP.NET web application using
VB.NET.

Thanks,,,,, Cliff

Nov 18 '05 #6
Hi Cliff,

To declare the body tag as HtmlGenericCont rol, you can just add follwong
line to the code behind:

Public Class WebForm1
Inherits System.Web.UI.P age

...

Private designerPlaceho lderDeclaration As System.Object

...

Just like declaring a Button or Datagrid on the page.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #7
I wanted to add a note to this previous post.

If you have a Stylesheet attached to the page, the values in the stylesheet
will override the values you set with the code snipett below, giving the
appearance that it did not work.

Thanks,,,,, Cliff
"Cliff Cavin" <Cl********@hot mail.com> wrote in message
news:e$******** ******@TK2MSFTN GP10.phx.gbl...
Finally! I got it.

To programatically , using VB Code Behind, change the background color at
Page_Load time, do this:

1) Bring up the HTML for the aspx page.
2) Change the <body> tag to <body id="PageBody" runat="server")
3) Bring up the code behind and place this code in the Page_Load event, or
actuall I guess it could go anywhere:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyBody As New HtmlGenericCont rol
MyBody = Page.FindContro l("PageBody")
MyBody.Attribut es("bgcolor") = "#FF00FF"
End Sub
Note: The Page.FindContro l seems to to be the missing link.
Missing from all VS MSDN Library.
Missing from all newsgroup posts.

If you leave out the line: MyBody = Page.FindContro l("PageBody")
the solution will still compile and run. It just won't change the
background color.

Unfortuately, the documentation that comes with VS is all from the point of view that you are NOT using code behind. And there *are* a few small
differences between using code behind and not using code behind.

Well, there goes another 8 hours of my life researching something that
should be stupid simple.

I am guessing this same idea could be extended to manipulate any of the
otherwise unreachable DOCUMENT properties from within code (although I have not had the courage to try yet).

Hope this helps the next guy with the same *simple* question.

Cliff

"Cliff Cavin" <Cl********@hot mail.com> wrote in message
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
How do I programatically change the background color of an aspx page in
code?

Is there something like Page.BgColor = "#FFFFFF" ?

For that matter, how do I access any of the DOCUMENT properties in code?

I am using Visual Studio 2003, building an ASP.NET web application using
VB.NET.

Thanks,,,,, Cliff


Nov 18 '05 #8

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

Similar topics

2
5286
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance RWD <script type='text/javascript'>
2
3192
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as below:- <% tBegin = request("beginww") tEnd = request("endww") tYear = request("wwyear") %> <body>
0
1695
by: The Coolest Dolphin | last post by:
OnMouseOver & OnMouseOut event on tablerow to change backcolor of row Hi everyone, I'm looking for a way to use a mouseover/mouseout event (normally done via javascript) via Visual Studio.Net. In the past I succeeded doing this via:
1
1367
by: Mirco | last post by:
I must make a aspx page that make these single steps: 1. when I open it is green 2. when I click a button it is blue 3. when I click the same button it is red alternate 2 and 3 I have written this code but it does not work. Which thing I am mistaking?
1
1176
by: Dmitry N.Ananyev | last post by:
Hello friends! I am start my first ASP practic in VS2005. **** My table ****************************** <table> <tr> <td></td> </tr> <tr>
3
2861
by: Cliff Cavin | last post by:
How do I programatically change the background color of an aspx page in code? Is there something like Page.BgColor = "#FFFFFF" ? For that matter, how do I access any of the DOCUMENT properties in code? I am using Visual Studio 2003, building an ASP.NET web application using VB.NET.
6
3721
by: acord | last post by:
Hi, I want to change the background color of a ul/li row, but the following code is not working as I expected. It works in <table><tr>... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
1
1355
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is there an easy way to change the background color of the page in the code-behind? thanks, rodchar
1
2060
by: nsteiner | last post by:
Hi all On my web page I have a 3 column table. The first cell changes background color when mouseover event occurs. Something like this : <TR><TD onMouseOver="this.bgColor='#00CC00'" onMouseOut="this.bgColor='#F0FFF0'" >name</TD> <TD>number</TD> <TD>address</TD><TR> This works fine.
0
7666
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...
0
7888
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. ...
0
8108
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...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
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...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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
0
925
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...

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.