Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi All,

I have a label defined like this:
<asp:Label ID="lblWarning" runat="server" ForeColor="Red" Visible="False" Height="19px" Width="276px">

I tried to clear the text of a label like this :
XML
function ChangeProperty() {
            var b = document.getElementById('<%=lblWarning.ClientID%>');
if (b!=null)

            {
                b.innerText = "";
}

     }



This is not working.Please help.

Thanks.
Posted
Comments
Afzaal Ahmad Zeeshan 10-Jun-15 15:36pm    
How is it not working? Check in the console to see what error is it giving, press F12 to get the developer tools active. Then tell us the error message to get help.

1 solution

When you set the Visible property of a server side control to false it not even rendered to the client, so your code will not found it at all (b will be null)...
If you want to make it visible/invisible on the client you have to play with client side attributes...
Set display or clear the display attribute...
ASP.NET
<asp:label id="lblWarning" runat="server" forecolor="Red" height="19px" width="276px" xmlns:asp="#unknown"></asp:label>

XML
function ChangeProperty() {
  var b = document.getElementById('<%=lblWarning.ClientID%>');
  if (b!=null)
  {
    if(b.style.display == "none")
    {
      b.style.display = "";
    }
    else
    {
      b.style.display = "none";
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900