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

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(sender As Object, e As System.EventArgs)
bg.Attributes.Add("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 4480
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******@newsgroups.nospam> wrote in message
news:eX**************@TK2MSFTNGP14.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(sender As Object, e As System.EventArgs)
bg.Attributes.Add("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**************@TK2MSFTNGP09.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******@newsgroups.nospam> wrote in message
news:eX**************@TK2MSFTNGP14.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(sender As Object, e As System.EventArgs)
bg.Attributes.Add("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******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.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**************@TK2MSFTNGP09.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******@newsgroups.nospam> wrote in message
news:eX**************@TK2MSFTNGP14.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(sender As Object, e As System.EventArgs)
bg.Attributes.Add("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("ForeColor")%>"
<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**************@TK2MSFTNGP12.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******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.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**************@TK2MSFTNGP09.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******@newsgroups.nospam> wrote in message
news:eX**************@TK2MSFTNGP14.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(sender As Object, e As System.EventArgs)
bg.Attributes.Add("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.Attributes["bgcolor"] = ColorSelect.Value;
}
</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>Gainsboro</option>
<option>LemonChiffon</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 HtmlGenericControl.

All you'd need to do is submit the form programmatically,
with whatever value you are going to give to "Body1.Attributes["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******@newsgroups.nospam> wrote in message
news:OW**************@TK2MSFTNGP14.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("ForeColor")%>"

<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**************@TK2MSFTNGP12.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******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.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**************@TK2MSFTNGP09.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******@newsgroups.nospam> wrote in message
news:eX**************@TK2MSFTNGP14.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(sender As Object, e As System.EventArgs)
> bg.Attributes.Add("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 programmatically
set the bgcolor for page body in codebehind, we need to mark the body as
"runat=server" 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.Page
{
protected System.Web.UI.WebControls.TextBox txtColor;
protected System.Web.UI.WebControls.Button btnSubmit;
protected HtmlGenericControl bd;
===========================

private void btnSubmit_Click(object sender, System.EventArgs e)
{
System.Drawing.Color bgcolor =
System.Drawing.ColorTranslator.FromHtml(txtColor.T ext);

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**************@TK2MSFTNGXA03.phx.gbl...
Hi Gary,

I think Juan's suggestion is good. Also, if you do need to
programmatically
set the bgcolor for page body in codebehind, we need to mark the body as
"runat=server" 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.Page
{
protected System.Web.UI.WebControls.TextBox txtColor;
protected System.Web.UI.WebControls.Button btnSubmit;
protected HtmlGenericControl bd;
===========================

private void btnSubmit_Click(object sender, System.EventArgs e)
{
System.Drawing.Color bgcolor =
System.Drawing.ColorTranslator.FromHtml(txtColor.T ext);

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="setcursor".... 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%***************@TK2MSFTNGXA03.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
Hi Gary,

Thanks for your followup.

Yes, I did find the problem you mentioned. It is caused by the
runat='server' control's "onload" is always parsed ast server-side event.
Currently I found that we can use code behind to programmatically assign
the client-side onload script handler for the <body runat="server" > ...
e.g:

======================
<script language="javascript">
function mybd_load()
{
alert("mybd_load...");
}
</script>
</head>
<body id="mybd" runat="server" onclick="mybd_load();">
=========================

=====================
Public Class bodyPage
Inherits System.Web.UI.Page

Protected mybd As HtmlGenericControl

................................

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

mybd.Attributes("onload") = "mybd_load();"
Response.Write("<br/>" & mybd.Attributes("onload"))
End Sub
........................
=====================

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.

Mar 27 '06 #11
Thanks, that does it. but....

you don't need the Response.Write("<br/>" & mybd.Attributes("onload")),
all that does is put "<br/>mybd_load()" as the first line of the rendered
html.

anyway that solves the problem :)

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

Thanks for your followup.

Yes, I did find the problem you mentioned. It is caused by the
runat='server' control's "onload" is always parsed ast server-side event.
Currently I found that we can use code behind to programmatically assign
the client-side onload script handler for the <body runat="server" > ...
e.g:

======================
<script language="javascript">
function mybd_load()
{
alert("mybd_load...");
}
</script>
</head>
<body id="mybd" runat="server" onclick="mybd_load();">
=========================

=====================
Public Class bodyPage
Inherits System.Web.UI.Page

Protected mybd As HtmlGenericControl

...............................

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

mybd.Attributes("onload") = "mybd_load();"
Response.Write("<br/>" & mybd.Attributes("onload"))
End Sub
.......................
=====================

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.

Mar 28 '06 #12
Thanks for your response.

Yes, "Response.Write("<br/>" & mybd.Attributes("onload"))" is my test code
:P. Sorry for the confusion.
Also, I'm glad that this is of assistance to you.

Have a good day!

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.

Mar 28 '06 #13

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

Similar topics

31
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...
6
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...
8
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...
3
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...
1
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...
2
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...
3
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....
4
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...
2
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,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.