I am trying to use javascript to set the background color of a label when a link button is clicked.
However, the background will flash the desired color and then fall back to no background. Below I have the javascript function as well as the control in question.
I’ve tried forcing a redraw with a display=’none’,display=” but no avail.
Also, I’ve tried making the label not run at server by making it a standard control.
I’ve also put breaks on both areas the style is set, and the LightGreen is called, but the blank is not, so not sure where the background is being blanked out as this is not being specified anywhere else.
Thanks, James
The Label
<asp:Label runat="server" Font-Bold="true" id="lblCustomer">Customer:</asp:Label>
The Javascript
function CheckUncheckAll(clientID, listID, check) {
var chk = clientID.getElementsByTagName("input");
for (var i = 0; i < chk.length; i++) {
chk[i].checked = check;
}
if (check) {
document.getElementById(listID.id).style.backgroundColor = "LightGreen";
}
else {
document.getElementById(listID.id).style.backgroundColor = "";
}
}
The Code Behind
lbCustomerAll.Attributes.Add("onclick", "CheckUncheckAll(" + ckbxlstCustomer.ClientID + ", " + lblCustomer.ClientID + ", true)");
What if you do something like:
This will prevent the default behavior of the link button from firing.