Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:24:38+00:00 2026-05-31T21:24:38+00:00

Hey guys I’m writing a simple web program to get my feet wet in

  • 0

Hey guys I’m writing a simple web program to get my feet wet in C#.Net and ASP.Net and I’m a little confused.

basically what I want to do is have a drop down box where the user can select the color they want the background of the page to be, but I can’t find the property to do it dynamically like that.

not that it matters but I’m using visual studio 2010.

Any ideas?

Please and thanks!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdSubmit_Click(object sender, EventArgs e)
    {
        if (txtName.Text == "")
        {

        }
        else
        {
            lblName.Visible = true;
            lblName.Text = "Well hello there " + txtName.Text + "!";
            lblColor.Visible = true;
            ddlColors.Visible = true;
        }
    }
    protected void ddlColors_SelectedIndexChanged(object sender, EventArgs e)
    {
        int strDdlValue = Convert.ToInt32(ddlColors.SelectedValue);
        switch (strDdlValue)
        {
            case 1:
                Body.Style["background-color"] = "Red";
                break;
            case 2:
                Body.Attributes["bgcolor"] = "blue";
                break;
            case 3:
                Body.Attributes["bgcolor"] = "magenta";
                break;
            case 4:
                Body.Attributes["bgcolor"] = "green";
                break;
            default:
                break;
        }
        lblBye.Visible = true;
    }
}

SOURCE:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body id="Body" bgcolor="#3366ff" runat="server">
<form id="form1" runat="server" visible="True">
<div align="center" style="font-size: medium; font-weight: bold" >

    <asp:Label ID="lblWelcome" runat="server" Text="Welcome to WebGreeting!"></asp:Label>
    <br />
    <br />
    <br />
    <asp:Label ID="lblInstruction1" runat="server" 
        Text="Please enter your name in the text box below:"></asp:Label>
    <br />
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
    <asp:Button ID="cmdSubmit" runat="server" onclick="cmdSubmit_Click" Text="Submit!" />
    <br />
    <br />
    <br />
    <asp:Label ID="lblName" runat="server"></asp:Label>
    <br />
    <br />
    <br />
    <asp:Label ID="lblColor" runat="server" Text="What's your favorite color?" 
        Visible="False"></asp:Label>
    <br />
    <br />
    <br />
    <asp:DropDownList ID="ddlColors" runat="server" 
        onselectedindexchanged="ddlColors_SelectedIndexChanged" Visible="False">
        <asp:ListItem></asp:ListItem>
        <asp:ListItem>Red</asp:ListItem>
        <asp:ListItem>Green</asp:ListItem>
        <asp:ListItem>Blue</asp:ListItem>
        <asp:ListItem>Yellow</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <br />
    <asp:Label ID="lblBye" runat="server" Text="I hope you had a nice day!" 
        Visible="False"></asp:Label>
    <br />

</div>
</form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:24:40+00:00Added an answer on May 31, 2026 at 9:24 pm
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
        <title>Untitled Page</title> 
    </head> 
    <body id="Body" runat="server"> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged"> 
            <asp:ListItem>1</asp:ListItem> 
            <asp:ListItem>2</asp:ListItem> 
            <asp:ListItem>3</asp:ListItem> 
            <asp:ListItem>4</asp:ListItem> 
        </asp:DropDownList> 
    </div> 
    </form> 
    </body> 
    </html> 
    

    Code Behind:

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    
        { 
        int strDdlValue = Convert.ToInt32(DropDownList1.SelectedValue); 
        switch (strDdlValue) 
            { 
            case 1: 
                Body.Attributes["bgcolor"] = "Red"; 
                break; 
            case 2: 
                Body.Attributes["bgcolor"] = "blue"; 
                break; 
            case 3: 
                Body.Attributes["bgcolor"] = "magenta"; 
                break; 
            case 4: 
                Body.Attributes["bgcolor"] = "green"; 
                break; 
            default: 
                            break; 
            } 
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I always get confused by this so it's not exactly my strong
Hey guys im trying to get a simple button masher up, What i want
Hey Guys, here is my code for this, the only help i get from
Hey guys, I'm writing a word wrap function to format console text in C++.
Hey guys I was wondering if someone could provide a little help. I've been
Hey guys I was wondering if there is a way to get a certain
Hey guys, I'm trying to get my head around LINQ and FP, so forgive
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey guys I managed to get a text input and select box to updated
Hey guys I'm building my first website and I cannot figure how to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.