Changing Page BackGround Color Programmatically

There are several things this sample shows, including creating an arraylist and binding it to a DropDownList, but the main thrust of the sample is to show how to easily change the background color of the existing page programmatically.

<html>
<head>
<meta name=”GENERATOR” Content=”ASP Express 2.0″>
<title>Change Body Color</title>
<script language=”VB” runat=”server”>
Sub Page_Load(Source as Object, E as EventArgs)

if not Page.IsPostBack then
Dim ColorList as ArrayList= new ArrayList()
ColorList.Add (“AliceBlue”)
ColorList.Add (“AntiqueWhite”)
ColorList.Add (“Aquamarine”)
ColorList.Add (“BlanchedAlmond”)
ColorList.Add (“CadetBlue”)
ColorList.Add (“Chocolate”)
dd1.datasource=ColorList
dd1.databind()
end if
End Sub

Sub changecolor(Source as Object, E as EventArgs)
bdy.attributes(“bgcolor”)=dd1.SelectedItem.Text
End Sub
</script>

</head>
<body runat=”server” id=”bdy”>
<Form id=”form1″ runat=”server”>
<asp:DropDownList id=”dd1″ runat=”server” /><asp:Button id=”button1″ Text=”Change Background Color” onclick=”changecolor” runat=”server” />
</Form>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>