Changing Page bgColor from code

  • Thread starter Thread starter GaryDean
  • Start date Start date
G

GaryDean

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

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.
 
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/
===================================
 
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.
 
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
 
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.)
 
Back
Top