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.
vikaslalkiya
Member
62 Points
93 Posts
javascript not work for change label text color in .cs file
May 01, 2012 06:14 AM|LINK
<head runat="server">
<title></title>
<script type="text/javascript">
{
var hiddenControl = '<%= hdnDirtyFlag.ClientID %>';
document.getElementById(hiddenControl).style.color = "red";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="hdnDirtyFlag" runat="server" />
<asp:Label ID="Label1" runat="server" Text="hello"></asp:Label>
</form>
</body>
...cs file
protected void Page_Load(object sender, EventArgs e)
{
hdnDirtyFlag.Value = "Label1";
}
nijhawan.sau...
All-Star
16430 Points
3173 Posts
Re: javascript not work for change label text color in .cs file
May 01, 2012 06:21 AM|LINK
You are changing the color for hiddenfield in your code not label.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: javascript not work for change label text color in .cs file
May 01, 2012 06:23 AM|LINK
change your code to
document.getElementById("Label1").style.color = "red";
Ruchira
All-Star
43056 Points
7040 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.