Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing Page bgColor from code

0 views
Skip to first unread message

GaryDean

unread,
Mar 11, 2006, 2:01:06 PM3/11/06
to
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


Erik Funkenbusch

unread,
Mar 11, 2006, 3:35:26 PM3/11/06
to

I'm not sure what version of ASP.NET you're using, but if you're using 2.0,
and the document type is XHTML, then bgcolor is deprecated. You would
instead set the style background-color: #ff9933; instead. Something like
this (I haven't test this code, so the exact syntax may not be correct).

Dim style as string = bg.Attributes("style")
s = s & "background-color: #ff9933;"
bg.Attributes("style") = s

This, of course, assumes that there isn't already a background-color style
(though it would probalby still work). So you might have to add some code
to determine if there is already one, and replace it if there is.

Juan T. Llibre

unread,
Mar 11, 2006, 3:47:42 PM3/11/06
to
There's been sample code to do that since ASP.NET 1.0.

See :
http://samples.gotdotnet.com/quickstart/aspplus/samples/apps/cookies1/VB/cookies1.aspx
for a sample doing that with cookies.

and

http://samples.gotdotnet.com/quickstart/aspplus/samples/apps/session1/VB/session1.aspx
for a sample doing it with session values.


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/
===================================
"Erik Funkenbusch" <er...@despam-funkenbusch.com> wrote in message
news:1n5r8pmq...@funkenbusch.com...

Symphani

unread,
Mar 11, 2006, 4:12:16 PM3/11/06
to
This is the small modification that u hav to do in the code:
instead of: "<body MS_POSITIONING="GridLayout" runat="server" id="bg">"
Just recode it to: "<body> <form id="bg" runat="server">
.........</form> </body>"
And the rest is same.
just like recoding it with the actual source id from html tags.

Tina

unread,
Mar 11, 2006, 4:48:26 PM3/11/06
to
that doesn't work. the id in form already says id="Form1" and form1 is
unrecognized.

I forgot to indicate that I'm using 1.1 so I'll repost.

Thanks,
Gary

"Symphani" <symp...@gmail.com> wrote in message
news:1142111536.3...@i40g2000cwc.googlegroups.com...

GaryDean

unread,
Mar 11, 2006, 4:49:49 PM3/11/06
to
oops. forgot to say I'm using 1.1. I'll repost

--
Regards,
Gary Blakely


"Erik Funkenbusch" <er...@despam-funkenbusch.com> wrote in message
news:1n5r8pmq...@funkenbusch.com...

Steven Cheng[MSFT]

unread,
Mar 12, 2006, 10:53:40 PM3/12/06
to
Hi Gary,

We've found your new reposted thread in this group and posted suggestion
there. If you feel it convenient that we continue to discuss there, please
feel free to post in that thread.

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

0 new messages