No point of changing the color in hidden field since it will never get shown at client side. Change the above code to below and it will work for the label. Also I don't see that you've defined any function. placing the script inside curly braces alone would
not work.
<script type="text/javascript">
window.onload = function test(){
var hiddenControl = '<%= Label1.ClientID %>';
document.getElementById(hiddenControl).style.color = "red";
}
</script>
Following link will help you to learn about javascripts.
Ruchira
All-Star
42885 Points
7019 Posts
MVP
Re: javascript not work for change label text color in .cs file
May 01, 2012 07:14 AM|LINK
Hello,
No point of changing the color in hidden field since it will never get shown at client side. Change the above code to below and it will work for the label. Also I don't see that you've defined any function. placing the script inside curly braces alone would not work.
<script type="text/javascript"> window.onload = function test(){ var hiddenControl = '<%= Label1.ClientID %>'; document.getElementById(hiddenControl).style.color = "red"; } </script>Following link will help you to learn about javascripts.
http://www.w3schools.com/js/
What are you trying to achieve?
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.