473,831 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the background color

Hi,

Can someone tell me how to change the background color of a web page though
C#? I've tried various things that I have found on the web written in VB
but I haven't had much luck with them.

Thank you,
Glenn
Apr 5 '06 #1
7 8731
Hi Glenn,

Thank you for posting.

As for the programmaticall y change ASP.NET webform page's background color
question, I think we can mark the <body> element in the form as
runat="server", then we can use code to manipulate the <body> element's
style attributes in page's code behind. Also, are you using ASP.NET 1.1 or
2.0, for asp.net 1.1 since it is not using the partial class to compile
aspx and code behind, we still need to manually declare the control member
in the codebehind page class(if we mark the <body> as runat="server") .
Below is the code we need to modify in ASP.NET 2.0 page to programmaticall y
change the page's background:

for ASP.NET 2.0
=========in aspx ========
<body id="mybody" runat="server">

=======in codebehind=====
protected void Page_Load(objec t sender, EventArgs e)
{
mybody.Style[HtmlTextWriterS tyle.Background Color] = "#787878";
}

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.c om/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 6 '06 #2
Hi Steve,

I'm still on ASP 1.1, I have 2.0 here but I am concentrating on getting this
project done for the end of May before I convert over. Can you post how to
do this with 1.1?

Thank you,
Glenn
"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:QL******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Glenn,

Thank you for posting.

As for the programmaticall y change ASP.NET webform page's background color
question, I think we can mark the <body> element in the form as
runat="server", then we can use code to manipulate the <body> element's
style attributes in page's code behind. Also, are you using ASP.NET 1.1 or 2.0, for asp.net 1.1 since it is not using the partial class to compile
aspx and code behind, we still need to manually declare the control member
in the codebehind page class(if we mark the <body> as runat="server") .
Below is the code we need to modify in ASP.NET 2.0 page to programmaticall y change the page's background:

for ASP.NET 2.0
=========in aspx ========
<body id="mybody" runat="server">

=======in codebehind=====
protected void Page_Load(objec t sender, EventArgs e)
{
mybody.Style[HtmlTextWriterS tyle.Background Color] = "#787878";
}

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.c om/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 6 '06 #3
<html>
<head>
<script language="C#" runat="server">
void SubmitBtn_Click (object Source, EventArgs e) {
Body.Attributes["bgcolor"] = ColorSelect.Val ue;
}
</script>
</head>

<body id=Body runat=server>

<h3><font face="Verdana"> HtmlGenericCont rol Sample</font></h3>
<form runat=server>
<p>
Select a background color for the page: <p>
<select id="ColorSelect " runat="server">
<option>White </option>
<option>Wheat </option>
<option>Gainsbo ro</option>
<option>LemonCh iffon</option>
</select>
<input type="submit" runat="server" Value="Apply" OnServerClick=" SubmitBtn_Click ">
</form>
</body>
</html>


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:O8******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

Can someone tell me how to change the background color of a web page though
C#? I've tried various things that I have found on the web written in VB
but I haven't had much luck with them.

Thank you,
Glenn


Apr 6 '06 #4
What I think I need is how to manually declare the control member. I tried
doing this:

protected System.Web.UI.W ebControls.Styl e body;

But I guess its not a "Style" because it didn't work. I'm not sure what to
call it.

Thank you,
Glenn
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Ov******** ******@TK2MSFTN GP02.phx.gbl...
<html>
<head>
<script language="C#" runat="server">
void SubmitBtn_Click (object Source, EventArgs e) {
Body.Attributes["bgcolor"] = ColorSelect.Val ue;
}
</script>
</head>

<body id=Body runat=server>

<h3><font face="Verdana"> HtmlGenericCont rol Sample</font></h3>
<form runat=server>
<p>
Select a background color for the page: <p>
<select id="ColorSelect " runat="server">
<option>White </option>
<option>Wheat </option>
<option>Gainsbo ro</option>
<option>LemonCh iffon</option>
</select>
<input type="submit" runat="server" Value="Apply" OnServerClick=" SubmitBtn_Click "> </form>
</body>
</html>


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:O8******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

Can someone tell me how to change the background color of a web page though C#? I've tried various things that I have found on the web written in VB but I haven't had much luck with them.

Thank you,
Glenn


Apr 6 '06 #5
body is a Generic HTMLControl

Try:

protected GenericHtmlCont rol Body;


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:e6******** ******@TK2MSFTN GP02.phx.gbl...
What I think I need is how to manually declare the control member. I tried
doing this:

protected System.Web.UI.W ebControls.Styl e body;

But I guess its not a "Style" because it didn't work. I'm not sure what to
call it.

Thank you,
Glenn
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Ov******** ******@TK2MSFTN GP02.phx.gbl...
<html>
<head>
<script language="C#" runat="server">
void SubmitBtn_Click (object Source, EventArgs e) {
Body.Attributes["bgcolor"] = ColorSelect.Val ue;
}
</script>
</head>

<body id=Body runat=server>

<h3><font face="Verdana"> HtmlGenericCont rol Sample</font></h3>
<form runat=server>
<p>
Select a background color for the page: <p>
<select id="ColorSelect " runat="server">
<option>White </option>
<option>Wheat </option>
<option>Gainsbo ro</option>
<option>LemonCh iffon</option>
</select>
<input type="submit" runat="server" Value="Apply"

OnServerClick=" SubmitBtn_Click ">
</form>
</body>
</html>


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:O8******** ******@TK2MSFTN GP03.phx.gbl...
> Hi,
>
> Can someone tell me how to change the background color of a web page though > C#? I've tried various things that I have found on the web written in VB > but I haven't had much luck with them.
>
> Thank you,
> Glenn
>
>



Apr 6 '06 #6
I got it to work like this:

ASP Code:
<body runat="server" id="body">

Code Behind:
protected System.Web.UI.H tmlControls.Htm lGenericControl body;
...
string strColor =
System.Configur ation.Configura tionSettings.Ap pSettings["bgColor"];
body.Attributes .Add("bgColor", strColor);

Thank you for your help,
Glenn

"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:O8******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

Can someone tell me how to change the background color of a web page though C#? I've tried various things that I have found on the web written in VB
but I haven't had much luck with them.

Thank you,
Glenn

Apr 6 '06 #7
re:
Thank you for your help
You're more than welcome, Glenn.
I'm glad you're up and running again.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..I got it to work like this:

ASP Code:
<body runat="server" id="body">

Code Behind:
protected System.Web.UI.H tmlControls.Htm lGenericControl body;
...
string strColor =
System.Configur ation.Configura tionSettings.Ap pSettings["bgColor"];
body.Attributes .Add("bgColor", strColor);

Thank you for your help,
Glenn

"Glenn Hanna" <gm*****@newsgr oups.nospam> wrote in message
news:O8******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

Can someone tell me how to change the background color of a web page

though
C#? I've tried various things that I have found on the web written in VB
but I haven't had much luck with them.

Thank you,
Glenn


Apr 6 '06 #8

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

Similar topics

3
2018
by: Billy | last post by:
Hello, I'm having a problem dynamically changing the color of a table background. I'm not sure exactly how to word this, but I'll give an example. I have a function called greentored(propname) i want to be able to change the following to a different color: document.all.propname.style.visibility
1
1760
by: P.Singh | last post by:
hi all i am designing a website for a charity origanisation. they cater towards the senior crowd. i would like to have choice by which the user can change the background as required (like beige/grey/aqua etc.) and also the text color/font and browse the site with that background and text color . will i need to make different copies of the site and link them together.
31
5735
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a calendar, 7 across by whatever needed down, and I manually create it each month - not a big deal. Every day I go in and darken the background color of the current day's cell by changing the appropriate <TD> entry to <TD bgcolor="c63800"> and...
1
6733
by: Omar Llanos | last post by:
How can I change the background color of an MDI form? I read in msdn that it takes the background of windows (and not the BackColor) but I wanted to really make sure. I know that in VC it can be done. Thanks.
4
3793
by: Chris Mahoney | last post by:
Hi Currently I am setting the background image of my page by using the following code: <style type="text/css"> BODY { BACKGROUND-IMAGE: url(myimage.jpg) } </style> What I would like to do is change the background image dynamically. My guess
12
4555
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in another forum from Peter Huang that said that an id="bg" as follows... <body MS_POSITIONING="GridLayout" runat="server" id="bg"> then we could do the following in our codebehind file....
8
3935
by: Bosconian | last post by:
I have two multiple select inputs. Initially the first contains a bunch of items and the second is empty. Using a common method, I move items back and forth by double clicking on them. This portion works perfectly, but I would also like to change the background color of the select element with the current focus. I have defined the following classes: ..selected {
4
1818
by: gescom | last post by:
I'm sort of locked into a template from this software my company bought, and it's very restrictive. All color schemes and layouts are site wide only, which creates a bit of a hassle for some pages. The one think I'm looking for is how to change a single page's background color. It appears that the site's layout is a table, so I guess the question is how do I change the background color of a cell within a table indirectly. I only have...
1
2115
by: printline | last post by:
Hi' I have a problem with changing the background color in a table cell when i click on the content in the cell. Here is my code: <script type="text/javascript"> var ie = document.all var ns = document.getElementById && !ie
5
5267
by: jeddiki | last post by:
I want to change the default background color of my select box. Here is the problem: Link to form with color select Notice in the color selector, the background color that I have given it it the option statement changes on hover to a blue/gray. Instead of background color change I would like the text to BOLD. So on hovering over green, the text "green" goes green (bold) but
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10496
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...
1
10538
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10210
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
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7750
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
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.