Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am able to do one part of it i.e. on click label1--> data will be shown on label2. Now please tell me how to hide data on label2 by clicking label1.


code:

C#
<script type="text/C#" runat= "server">
    
    protected void Page_Load(object sender, EventArgs e)
    {      
        label1.Attributes.Add("onclick", "label2show()");
    }
</script>


JavaScript
<script type="text/javascript">
  function label2show() 
   {
     document.getElementById('label2').innerHTML = 'show data'; 
   }
</script> 


<asp:Label runat="server" ID="label1">Press it to show and hide data on label 2</asp:Label>
<asp:Label runat="server" ID="label2"></asp:Label>
Posted
Updated 8-Mar-10 23:44pm
v3

Change the javascript function to this:

JavaScript
function label2show() 
 {
      if(document.getElementById('label2').innerHTML == '')
          document.getElementById('label2').innerHTML = 'show data'; 
      else
          document.getElementById('label2').innerHTML = '';
 }
 
Share this answer
 
Thanks a lot ankur. Its so simple
I have to kick my a** for this silly mistake
 
Share this answer
 
can u please explain little more..How can we click on Label?...
 
Share this answer
 
See above I have written the code for adding click event on label using c#.
 
Share this answer
 
you can also use visible property of label like

label1.visible=false;
 
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