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

tanaya80Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

-sg-Commented:
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

0
tanaya80Author Commented:
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.




0
-sg-Commented:
Ok, cool.  Just put the script block at the bottom of the html code of the control like I have attached.

If you find that it is still not working, check the page source from the browser and see if asp.net has renamed the client ID's.  It will do this if using master pages for example.  If that's the case, then simply replace

getElementById("Checkbox1")

with

getElementById("<%=this.Checkbox1.ClientID%>")

assuming you are using C#
    <script type="text/javascript">
        document.getElementById("hidethis").style.display = ((document.getElementById("Checkbox1").checked)?'block':'none');
    </script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Internet Marketing

From novice to tech pro — start learning today.