Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting form properties in code
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00873706
Message ID:
00874693
Views:
15
Doru,

In my example I placed the code to change the background color in the Click event of a button. The in Code-behind, I would put the following code:
void SubmitBtn_Click(object Source, EventArgs e)
{
    Body.Attributes["bgcolor"] = ColorSelect.Value;
}
This allows the code to run when the button on the page is clicked.

>Hi Cathi,
>I am trying to figure out what to do with this code - as I said I am less than a beginner in web programming.
>It seems that everything comes in bits and pieces, but there is very little help in how to put them together. The assumption that before ASP.NET you did ASP and web programming is not true for me, so I am looking at tones of code samples like yours and don't yet know how to put them together. I actually have some other samples of user controls, and server controls...
>I believed that from VS.NET, I'll open a project, drop a selection control from Toolbox - Web Controls, and use C# switch structure to set the Body.bgcolor. I can actually change the backcolor of a textbox in this way. For the backcolor of the page though, it looks that for this I must use some sort of script, I have no idea why.
>I hope I'll figure it out some day, but is very frustrating...
>Thanks for your patience!
>
>>Hi Doru,
>>
>>I appologize. I gave you code for WinForms, not WebForms. To change the color of the page, you set the Body.Attributes["bgcolor"] to the color to use. Here is a working example of how to do this:
>>
>>
>><%@ Page Language="C#" AutoEventWireup="True"
>><html>
>><head>
>>   <script runat="server">
>>      void SubmitBtn_Click(object Source, EventArgs e)
>>      {
>>         Body.Attributes["bgcolor"] = ColorSelect.Value;
>>      }
>>   </script>
>></head>
>>
>><body id=Body runat="server">
>>
>>   <h3>Updating Styles with the HtmlGenericControl</h3>
>>
>>   <form runat="server">
>>      <p>
>>      Select a background color for the page: <p>
>>      <select id="ColorSelect" runat="server">
>>         <option>White</option>
>>         <option>Wheat</option>
>>         <option>Gainsboro</option>
>>         <option>LemonChiffon</option>
>>      </select>
>>      <input type="submit" runat="server"
>>             Value="Apply" OnServerClick="SubmitBtn_Click">
>>   </form>
>></body>
>></html>
>>
>>
>>>Hi Cathi,
>>>Where do I put that code and what object is 'this' pointing to? I wanted to have code in the option button to change the color of the page.
>>>
>>>>Hi Doru,
>>>>
>>>>To change the background color of the form, you would do the following:
>>>>
>>>>
>>>>this.BackColor = Color.Blue
>>>>
>>>>
>>>>>I created a C# web form in VS.NET and set the background color of the form to blue. I added a 3 buttons option group and tryied to change the color of the form when selecting an option... I thought it would be something like this.parent.bgcolor = rgb(), but it seems that this is as far as the moon from what I wanted. I tryied to lookup how do you set proprties in code in C#, but found zero so far.
>>>>>I am at the begining of a C# for web in 21 days and some other C# and ASP.NET reading, but do I have to go from start to end before I can do the simplest things?
>>>>>I hesitated about opening this thread in C#, maybe chatter would've fit better given the stage that I am in with dotnet...
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform