I have set up an asp.net gridview, and when a user clicks on a cell in the gridiview it goes through a series of background color changes. On the first click the cell background turns yellow, on the second click it turns orange, on the third click it turns blue, etc. However, when I refresh the page, the background color reverts to white. I need the cells to keep their background color when the page is refreshed or closed and re-opened.
VB:
Private Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowCreated
'Changes background color on click (JavaScript)
For x As Byte = 1 To 13
e.Row.Cells(x).Attributes.Add("onclick", "toggle(this);")
Next
End Sub
JS:
function toggle(obj){
if (obj.style.backgroundColor == 'white') {
obj.style.backgroundColor = 'yellow';
} else if (obj.style.backgroundColor == 'yellow') {
obj.style.backgroundColor = 'orange';
} else if (obj.style.backgroundColor == 'orange') {
obj.style.backgroundColor = 'deepskyblue';
} else if (obj.style.backgroundColor == 'deepskyblue') {
obj.style.backgroundColor = 'lightgreen';
} else if (obj.style.backgroundColor == 'lightgreen') {
obj.style.backgroundColor = 'white';
} else {
obj.style.backgroundColor = 'white';
}}