Live Chat Icon For mobile
Live Chat Icon

How to change the BackgroundColor of a page based on the value selected in a DropdownList

Platform: ASP.NET| Category: Client Side Scripting

<asp:DropDownList id='DropDownList1' runat='server' AutoPostBack='True'>
	<asp:ListItem Value='Red'>Red</asp:ListItem>
	<asp:ListItem Value='Blue'>Blue</asp:ListItem>
	<asp:ListItem Value='Green'>Green</asp:ListItem>
</asp:DropDownList>

VB.NET


Page.RegisterClientScriptBlock('BodyStyle', '<style type=’text/css’>body{background-color: ' + DropDownList1.SelectedItem.Value + ';}</style>')

C#


Page.RegisterClientScriptBlock('BodyStyle', '<style type=’text/css’>body{background-color: ' + DropDownList1.SelectedItem.Value + ';}</style>');

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.