473,748 Members | 5,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing page bgcolor from code (repost)

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....

Private Sub Page_Load(sende r As Object, e As System.EventArg s)
bg.Attributes.A dd("BgColor", "#ff9933")
End Sub

However, I get the errror that bg is Private.

Is there a solution to this issue where bgcolor, and other attributes of the
document can be changed from codebehind code?
--
Regards,
Gary Blakely
Mar 11 '06 #1
12 4551
If that's all you want to do, why don't you simply do it,
by setting the <body background-color...> attribute ?

You aren't *really* attemptiong to change the background color
from code. You are just setting an arbitrary background color.

If that's all you want to do, why don't you just set it in the <body...>

Otherwise, use the code for the examples I posted.
Those samples allow users to select any background/foreground colors you want to allow.

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
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....

Private Sub Page_Load(sende r As Object, e As System.EventArg s)
bg.Attributes.A dd("BgColor", "#ff9933")
End Sub

However, I get the errror that bg is Private.

Is there a solution to this issue where bgcolor, and other attributes of the
document can be changed from codebehind code?
--
Regards,
Gary Blakely

Mar 11 '06 #2
Yes I REALLY want to set it at run time - please trust me on this. Not at
design time.

The reason why I don't simply set it in the body is because I want to set it
at run time.

your examples show it working but I can't see your code behind.

Maybe we are not communicating well. I want to find out how to set the
background color at run time from my code behind file.
--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
If that's all you want to do, why don't you simply do it,
by setting the <body background-color...> attribute ?

You aren't *really* attemptiong to change the background color
from code. You are just setting an arbitrary background color.

If that's all you want to do, why don't you just set it in the <body...>

Otherwise, use the code for the examples I posted.
Those samples allow users to select any background/foreground colors you
want to allow.

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
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....

Private Sub Page_Load(sende r As Object, e As System.EventArg s)
bg.Attributes.A dd("BgColor", "#ff9933")
End Sub

However, I get the errror that bg is Private.

Is there a solution to this issue where bgcolor, and other attributes of
the
document can be changed from codebehind code?
--
Regards,
Gary Blakely


Mar 11 '06 #3
re:
your examples show it working but I can't see your code behind.
The code for with sessions is at :
http://samples.gotdotnet.com/quickst...ze.aspx&font=3

and, for doing it with cookies, the code is at :
http://samples.gotdotnet.com/quickst...1/cookies1.src


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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. Yes I REALLY want to set it at run time - please trust me on this. Not at design time.

The reason why I don't simply set it in the body is because I want to set it at run time.

your examples show it working but I can't see your code behind.

Maybe we are not communicating well. I want to find out how to set the background color at run
time from my code behind file.
--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
If that's all you want to do, why don't you simply do it,
by setting the <body background-color...> attribute ?

You aren't *really* attemptiong to change the background color
from code. You are just setting an arbitrary background color.

If that's all you want to do, why don't you just set it in the <body...>

Otherwise, use the code for the examples I posted.
Those samples allow users to select any background/foreground colors you want to allow.

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
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....

Private Sub Page_Load(sende r As Object, e As System.EventArg s)
bg.Attributes.A dd("BgColor", "#ff9933")
End Sub

However, I get the errror that bg is Private.

Is there a solution to this issue where bgcolor, and other attributes of the
document can be changed from codebehind code?
--
Regards,
Gary Blakely

Mar 12 '06 #4
I see your solution working and I saw the tutorial on this at gotdotnet.
but this does not appear to be compatible with forms as they are used in
vs.net. for instance...

<body MS_POSITIONING= "GridLayout " style="color:<% =GetStyle("Fore Color")%>"
<form id="Form1" method="post" runat="server">

</form>

The GetStyle call as above and as in your code is not tollerated in vs.net.
I am unable to even return to the design view with that code as is.

As I said before, I (simply) want to find out how to set the background
color at run time from my code behind file. It seems there has to be a way
to reference the bgcolor in the Document from my codebehind.

--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:OE******** ******@TK2MSFTN GP12.phx.gbl... re:
your examples show it working but I can't see your code behind.


The code for with sessions is at :
http://samples.gotdotnet.com/quickst...ze.aspx&font=3

and, for doing it with cookies, the code is at :
http://samples.gotdotnet.com/quickst...1/cookies1.src


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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Yes I REALLY want to set it at run time - please trust me on this. Not
at design time.

The reason why I don't simply set it in the body is because I want to set
it at run time.

your examples show it working but I can't see your code behind.

Maybe we are not communicating well. I want to find out how to set the
background color at run time from my code behind file.
--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
If that's all you want to do, why don't you simply do it,
by setting the <body background-color...> attribute ?

You aren't *really* attemptiong to change the background color
from code. You are just setting an arbitrary background color.

If that's all you want to do, why don't you just set it in the <body...>

Otherwise, use the code for the examples I posted.
Those samples allow users to select any background/foreground colors you
want to allow.

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
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....

Private Sub Page_Load(sende r As Object, e As System.EventArg s)
bg.Attributes.A dd("BgColor", "#ff9933")
End Sub

However, I get the errror that bg is Private.

Is there a solution to this issue where bgcolor, and other attributes
of the
document can be changed from codebehind code?
--
Regards,
Gary Blakely


Mar 12 '06 #5
I think you're complicating your life needlessly.

If you don't like that method, use this :

<%@ Page Language="C#" AutoEventWireup ="True" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
Changing a Page's Background Color
</title>
<script runat="server">
void SubmitBtn_Click (object Source, EventArgs e)
{
Body1.Attribute s["bgcolor"] = ColorSelect.Val ue;
}
</script>
</head>
<body id="Body1" runat="server">
<h3>Changing a Page's Background Color</h3>
<form id="Form1" runat="server">
<p></p>
Select a background color for the page: <p></p>
<select id="ColorSelect " runat="server">
<option>White </option>
<option>Wheat </option>
<option>Gainsbo ro</option>
<option>LemonCh iffon</option>
</select>
<input id="Submit1" type="submit" runat="server" value="Apply" onserverclick=" SubmitBtn_Click "/>
</form>
</body>
</html>

---000---

You should be able to insert that code into code-behind,
almost as it is. I wrote it inline, because I prefer inline coding.

Notice that all I'm doing is adding an id attribute (body1) to the body,
and then changing the bgcolor of that HtmlGenericCont rol.

All you'd need to do is submit the form programmaticall y,
with whatever value you are going to give to "Body1.Attribut es["bgcolor"]

You can see the above code working at :

http://asp.net.do/WebSite2/CustomizeDemo.aspx

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:OW******** ******@TK2MSFTN GP14.phx.gbl...
I see your solution working and I saw the tutorial on this at gotdotnet. but this does not appear
to be compatible with forms as they are used in vs.net. for instance...

<body MS_POSITIONING= "GridLayout " style="color:<% =GetStyle("Fore Color")%>"

<form id="Form1" method="post" runat="server">

</form>

The GetStyle call as above and as in your code is not tollerated in vs.net. I am unable to even
return to the design view with that code as is.

As I said before, I (simply) want to find out how to set the background color at run time from my
code behind file. It seems there has to be a way to reference the bgcolor in the Document from my
codebehind.

--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:OE******** ******@TK2MSFTN GP12.phx.gbl...
re:
your examples show it working but I can't see your code behind.


The code for with sessions is at :
http://samples.gotdotnet.com/quickst...ze.aspx&font=3

and, for doing it with cookies, the code is at :
http://samples.gotdotnet.com/quickst...1/cookies1.src


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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Yes I REALLY want to set it at run time - please trust me on this. Not at design time.

The reason why I don't simply set it in the body is because I want to set it at run time.

your examples show it working but I can't see your code behind.

Maybe we are not communicating well. I want to find out how to set the background color at run
time from my code behind file.
--
Regards,
Gary Blakely
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
If that's all you want to do, why don't you simply do it,
by setting the <body background-color...> attribute ?

You aren't *really* attemptiong to change the background color
from code. You are just setting an arbitrary background color.

If that's all you want to do, why don't you just set it in the <body...>

Otherwise, use the code for the examples I posted.
Those samples allow users to select any background/foreground colors you want to allow.

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/
=============== =============== =====
"GaryDean" <Ga******@newsg roups.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
> 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....
>
> Private Sub Page_Load(sende r As Object, e As System.EventArg s)
> bg.Attributes.A dd("BgColor", "#ff9933")
> End Sub
>
> However, I get the errror that bg is Private.
>
> Is there a solution to this issue where bgcolor, and other attributes of the
> document can be changed from codebehind code?
>
>
> --
> Regards,
> Gary Blakely




Mar 12 '06 #6
Hi Gary,

I think Juan's suggestion is good. Also, if you do need to programmaticall y
set the bgcolor for page body in codebehind, we need to mark the body as
"runat=serv er" and assign an ID, also in codebehind, we need to explicitly
declare a protected control member fields to associate that tag. For
example:

<body id="bd" runat="server" >
=============== ====

public class BgColorPage : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box txtColor;
protected System.Web.UI.W ebControls.Butt on btnSubmit;
protected HtmlGenericCont rol bd;
=============== ============

private void btnSubmit_Click (object sender, System.EventArg s e)
{
System.Drawing. Color bgcolor =
System.Drawing. ColorTranslator .FromHtml(txtCo lor.Text);

bd.Style["BACKGROUND-COLOR"] =
System.Drawing. ColorTranslator .ToHtml(bgcolor );
}
=============== =======

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

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

Mar 13 '06 #7
Steven,
that was the answer! It was the declaration of bd as an htmlgeneric control
that was missing.
thanks for your help

--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:4l******** ******@TK2MSFTN GXA03.phx.gbl.. .
Hi Gary,

I think Juan's suggestion is good. Also, if you do need to
programmaticall y
set the bgcolor for page body in codebehind, we need to mark the body as
"runat=serv er" and assign an ID, also in codebehind, we need to explicitly
declare a protected control member fields to associate that tag. For
example:

<body id="bd" runat="server" >
=============== ====

public class BgColorPage : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box txtColor;
protected System.Web.UI.W ebControls.Butt on btnSubmit;
protected HtmlGenericCont rol bd;
=============== ============

private void btnSubmit_Click (object sender, System.EventArg s e)
{
System.Drawing. Color bgcolor =
System.Drawing. ColorTranslator .FromHtml(txtCo lor.Text);

bd.Style["BACKGROUND-COLOR"] =
System.Drawing. ColorTranslator .ToHtml(bgcolor );
}
=============== =======

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

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

Mar 17 '06 #8
You're welcome Gary,

Good luck!

Regards,

Steven Cheng
Microsoft Online Support

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

Mar 20 '06 #9
Steven,
I have an interesting complication related to putting a runat="server"
inside my body tag.

On one of my pages I was calling a Javascript function i.e. <body
onload="setcurs or".... where I am calling a javascript function. But since
the body is now a server control the page gets an error saying setcursor is
not a part of webform1.aspx.

Do you know of way to call the javascript function now that it has the
runat server?

--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:F%******** *******@TK2MSFT NGXA03.phx.gbl. ..
You're welcome Gary,

Good luck!

Regards,

Steven Cheng
Microsoft Online Support

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

Mar 27 '06 #10

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

Similar topics

31
5720
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...
6
1473
by: GaryDean | last post by:
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.... Private Sub Page_Load(sender As Object, e As System.EventArgs) bg.Attributes.Add("BgColor", "#ff9933")
8
2195
by: Radx | last post by:
Here in my web application, I have a data entry page with serval controls. Some of the controls have autopostback is set true. But the problem is when two or more people are entering data at the same time, in the middle of my data entry , it is brining someelse data on my screen. I look everywhere i could not find the solution. Please help me Radx
3
2338
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
1
4530
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I want only one instance of the FCKEditor on the screen at one time so I make tabs that the user can click and I store the values in variables behind the scenes. I change the CSS class on the link that is the currently selected one. I have a really...
2
1486
by: nick0123 | last post by:
Newbie-ish here... I have made a simple database in MS Access 2003 listing sports teams, their playing dates, opposition venues etc. The database has six tables, one for each sport. Exporting the first table as an asp page lets me view the details for that particular sport. To view all the other sports on the same page, I copied/pasted the sql code, replacing the names of the sport. Locally, this page takes about a second to...
3
1854
by: kang jia | last post by:
hi i am doing reply page for forum, users can reply for the specific topic they would like to reply. Firstly of all, when click the topic name in topic page. i will redirect them to reply page. the details of the topic will be retrieved from database, like 'detail' field, 'name'( name of the poster) 'email', 'date'. secondly, i will also retrieve all the replies from other users. and lastly is creating text box and text area to let the user...
4
3352
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters the comments and clicks the save button then the date and the date will be stored in the mysql database. This is working fine. But my problem is when, after the user had made an entry the date in the calendar for which an entry has made should be...
2
1456
by: suganya | last post by:
Hi I have a master page with <TD> columns defined in the table as <td bgcolor="#518643"> (which means bgcolor="green"). In one of my content pages, I have a dropdown with values such as blue, green. In that, if I select the value as blue, then all <TD>'s in Master page with bgcolor="#518643" should change as green. So that the use can customize their page according to their color selection.
0
8991
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...
1
9324
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
8243
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
6796
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
4606
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
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
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.