Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:22:57+00:00 2026-05-11T18:22:57+00:00

I have two tables on a webform. On a button click I want to

  • 0

I have two tables on a webform. On a button click I want to hide one and show the other. I gave them both an Id and I want to set the tables’ style=”display:”

I tried this in javaScript using a function and document.getelementbyid(id).style.display=’none’ but it did not work.

any ideas?

Solution:

OnClientClick="javascript: tbl2.style.display='';tbl1.style.display='none';return false;" 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:22:57+00:00Added an answer on May 11, 2026 at 6:22 pm

    I am assuming your tables are .net controls? If so, passing ‘id’ is not enough as .net does not assign the same server id as client-side id.

    You need to access the ClientID property of the .net control server-side to get it’s real client-side id:

    MyButton.OnClientClick = string.Format("{0}.style.display=''", ControlIWantToHide.ClientID);
    

    The above code shows how you would attach some javascript (please don’t call it java!) to a .net asp:button called MyButton and then have a client-side click on that hide a control called ControlIWantToHide.

    Note: the above may need tweaking to make it work across all browsers but the .net stuff is the important factor here and I suspect the ClientID is what you needed all along.

    Based on your responses to comments, the elements you are toggling are not .net controls but the button triggering them is, so: (based on the function posted by ebrown):

    <script type="text/javascript">
      function hide(id)
      {
         var element = document.getElementById(id);
    
         element.style.display='none';
      }
    
      function show(id)
      {
         var element = document.getElementById(id);
    
         element.style.display='block';
      }
    </script>
    

    You could trigger the toggle of an element in your page by attaching the javascript event handler server-side:

    MyButton.OnClientClick = "Show(tbl1);Hide(tbl2);return false;";
    

    ..which will display the element with id tbl1 and hide the one with tbl2. This will work providing the elements you are toggling are not .net controls – ie, they do not have the runat=”server” attribute. Remember, even though you are adding the javascript code to the asp:button on the server, it is only getting executed on the client when they click. Don’t forget to return ‘false’ as shown above to stop the default post-back behaviour of the asp:button.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have two sets of data (two tables) for patient records, one 1999-2003, the other
I have two tables. One is Employee_Mstr and other is EmployeeLeaveRequest_mstr . My data:
I have two tables one is heardt and other one is jud In heardt
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables in my MySQL database, one is a library of all
I have two tables inside a database. One stores unique userNames and a unique
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables. One table contains information about Assets, another Table about their
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables in db,and one owns a foreign key from another,the fllowing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.