Changing Page bgColor from code

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

Erik Funkenbusch

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

Symphani

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

Tina

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
 
S

Steven Cheng[MSFT]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top