Link to home
Start Free TrialLog in
Avatar of tanaya80
tanaya80

asked on

How do i hide a table row in asp.net web application

i am hiding a row of a table using javascript function in asp.net page .here, i m using a check box , when i ll checked the checkbox , it will hide the row , and when i ll un checked it will show the row, but i m getting problem when i am submitting the data by onclick button event the row is showing.means
 when the checkbox is checked means it will hide the row.but when i m submitting the data on Onclick event of the button the row is visible,means when the page is postback that time the row is visible.so i m getting problem.plz help me urgently.

<body>
<input id="Checkbox1" onClick="toggle()" type="checkbox" />
    
<table border="1">
<tr>
<td>Always visible</td>
</tr>
<tr id="hidethis" runat="server">
<td>Hide this</td>
    
</tr>
<tr>
<td>Always visible</td>
</tr>
</table>   
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
</body>
</html>
<script language="javascript" type="text/jscript">
    function toggle() 
{
 if( document.getElementById("hidethis").style.display=='none' )
{
  document.getElementById("hidethis").style.display = 'block';
  return true;
 }else{
  document.getElementById("hidethis").style.display = 'none';
  return false;
 }
}
    
    
    </script>

Open in new window

Avatar of -sg-
-sg-
Flag of Australia image

Here is the modified code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
      function toggle() 
      {
        document.getElementById("hidethis").style.display = ((document.getElementById("Checkbox1").checked)?'block':'none');
      }
    </script>
</head>
<body onload="toggle()">
<form runat="server" id="form1">
<asp:CheckBox runat="server" id="Checkbox1" onClick="toggle()" EnableViewState="True" checked="True" />
    
<table border="1">
<tr>
<td>Always visible</td>
</tr>
<tr id="hidethis" runat="server">
<td>Hide this</td>
    
</tr>
<tr>
<td>Always visible</td>
</tr>
</table>   
<asp:Button ID="Button1" runat="server" Text="Button" OnClick=Button1_Click  />
</form>
</body>
</html>

Open in new window

Avatar of tanaya80
tanaya80

ASKER

ok this is working fine in page level, but when i m using in .acx page means in a webcontrol or in a gridview then it is not working bcz how i will define the <body onload="to toggle()"> , is there any alternative solution.




ASKER CERTIFIED SOLUTION
Avatar of -sg-
-sg-
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial