How to change background color of a page in Asp.net through color picker
I'm developing a page in which I've given users an interactivity to change the background color of a page by clicking particular button. I am trying to find out through various sites but they are giving the information 开发者_JAVA技巧about how to change the background color of the text box or grid view. it is a bit like customization tool which you find in various sites like orkut and face book.
in the css/style
body
{
background-color:#000000;
}
But since it seems like you want to change the color on the fly then either in a javascript or code behind, change the class of the body to one that has background-color applied.
eg. for the code behind, make sure to set the with a runat="server" and id and then in code behind:
bodyId.Attributes["class"] = "test";
in css:
.test
{
background-color: #000000 !important;
}
Note that this will happen after a postback, while in the sites you mentioned it probably uses javascript.
You can use jQuery to modify the DOM on the fly, which would be perfect for your situation. Here's a quick sample using the .css() method. Once you make that change, you can store the value in a cookie or some other mechanism and use it next time the page is loaded.
//assumes MyButtonId is the id of the button the user clicks
$('#MyButtonId').click(function () {
//set the background-color of the body element to green
$('body').css('background-color', '#00F')
});
精彩评论