Hello i changed the div color with javascript using css. I have a div in repeater. How can i save the changes for ever. Like if color was yellow. After even user gets offline and gets online again , the yellow color will shows in the div. how can i use this with database? Im not good at JQuery codes. Cause of that i need your help.thanks.
my code which i have to save is :
$(document).ready(function () {
$(".divsec").on("click", function () {
$(this).css("background", "red");
});
});
my cs code is :
public static void InsertData(string Color)
{
OleDbConnection con = new OleDbConnection(Utility.GetConnection());
con.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO Temsilci(color) values(@color)", con);
cmd.Parameters.Add("color", Color);
cmd.ExecuteNonQuery();
con.Close();
}
and JS code for save color to database is :
$(document).ready(function () {
var color = '';
var clicks = 0;
$(".divsec").on("click", function () {
if (clicks == 1) {
$(this).css("background", "red");
}
else if (clicks == 2) {
$(this).css("background", "green");
}
else if (clicks == 3) {
$(this).css("background", "yellow");
}
else {
clicks = 0;
$(this).css("background", "transparent");
}
++clicks;
var x = $(this).css('backgroundColor');
hexc(x);
alert(color);
$.ajax({
url: 'default.aspx/InsertData',
type:'POST',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: "{Color:'" + color + "'}",
success: function () {
alert("Başarıyla kaydedildi");
},
error: function () {
alert("ERROR");
}
});
});
function hexc(colorval) {
var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
delete (parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
color = '#' + parts.join('');
}
});
it works fine but it send error when want to insert in database the COLOR value. And even if it perfectly will do it. I want to save the color of every div which user changed. how can i capture and save all values from repeater?