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" <> wrote in message
news:...
>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" <> wrote in message
> news:...
>> 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" <> wrote in message
>> news:%...
>>> 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" <> wrote in message
>>> news:...
>>>> 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" <> wrote in message
>>>> news:...
>>>>> 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
>>
>>
>
>