473,569 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show or Hide Elements

BRawn
28 New Member
I'm new to ASP.NET and I've been trying write code to show and hide certain elements on link's onclick event, but no matter what I try, nothing's working. Here's my scenario...

I have a MasterPageFile with 3 ContentPlaceHol ders. One for navigation (links which call the web forms which populate the main content placeholder), one for sub-categories (should there be) and one for the main content (which gets populated with web forms).

If I have a link which contains sub-categories, the sub-categories ContentPlaceHol der should populate with the links for each sub-category respectively. The idea is to use the sub-category links to jump to a specific place on the page.

The problem I'm having is that I can't seem to show or hide the sub-categories ContentPlaceHol der, no matter what I try. Here's what I've tried:

JavaScript...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3.  
  4.     function hideControl(controlID)
  5.     {
  6.         document.getElementById(controlID).style.visibility = 'hidden';
  7.     }
  8.  
  9.     function showControl(controlID)
  10.     {
  11.         document.getElementById(controlID).style.visibility = 'visible';
  12.     }
  13.  
  14. </script>
  15.  
  16.  


Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3.  
  4.     function hideControl(controlID)
  5.     {
  6.  
  7.         document.getElementById(controlID).style.display = 'block';
  8.     }
  9.  
  10.     function showControl(controlID)
  11.     {
  12.  
  13.         document.getElementById(controlID).style.display = 'none';
  14.     }
  15.  
  16. </script>
  17.  
  18.  



I tried using it like this (in my individual web forms):




Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" MasterPageFile="~/MasterPageFile.master" Title="Page Title" %>
  3. <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
  4.  
  5. <div class="bodyBackgroundLeft_ContentDIV"><a class="subMenuItems" href="#" style="text-decoration: none; padding-right: 92px; overflow: visible" onclick="showControl(Content3)">Link 1</a></div>
  6. <div class="ClassLink"><a class="subMenuItems" href="#" style="text-decoration: none" onclick="hideControl(Content3)">Link 2</a></div>
  7.  
  8.  


I've also tried using the code-behind file, like this:




Expand|Select|Wrap|Line Numbers
  1.  
  2.     void hideContentPlaceHolders()
  3.     {
  4.         ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("subContent");
  5.         cph.Visible = false;
  6.     }
  7.  
  8.     void showContentPlaceHolders()
  9.     {
  10.         ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("subContent");
  11.         cph.Visible = true;
  12.     }
  13.  
  14.  


...and calling it like this:




Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" MasterPageFile="~/MasterPageFile.master" Title="Page Title" %>
  3. <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
  4.  
  5. <div class="bodyBackgroundLeft_ContentDIV"><a class="subMenuItems" href="#" style="text-decoration: none; padding-right: 92px; overflow: visible" onclick="showContentPlaceHolders()">Link 1</a></div>
  6. <div class="ClassLink"><a class="subMenuItems" href="#" style="text-decoration: none" onclick="hideContentPlaceHolders()">Link 2</a></div>
  7.  
  8.  


The ContentPlaceHol der on my individual web forms look like this:



Expand|Select|Wrap|Line Numbers
  1.  
  2. <asp:Content ID="Content3" ContentPlaceHolderID="subContent" runat="server">
  3.     <div class="Link1"><a class="subMenuItems" href="#" style="text-decoration: none; overflow: visible">JumpToSection</a></div>
  4.     <div class="Link2"><a class="subMenuItems" href="#" style="text-decoration: none; overflow: visible">JumpToSection</a></div>
  5.     <div class="Link3"><a class="subMenuItems" href="#" style="text-decoration: none; overflow: visible">JumpToSection</a></div>
  6. </asp:Content>
  7.  
  8.  


And on my MasterPageFile. ..




Expand|Select|Wrap|Line Numbers
  1.  
  2. <div style="width: 185px; position: absolute; z-index: 5; margin-left: 0px; margin-top: 280px;">
  3.             <div class="bodyMenuTop"></div>
  4.             <div style="background-color: White; width: 185px; height: 220px;">
  5.  
  6.                 <asp:ContentPlaceHolder ID="subContent" runat="server">
  7.  
  8.                 </asp:ContentPlaceHolder>
  9.  
  10.             </div>
  11.             <div class="bodyMenuBottom"></div>
  12.         </div>
  13.  
  14.  


I usually get errors when loading pages using the JavaScript function, using the 'block' and 'none' display. The error message isn't really clear and it doesn't pin-point the location of the error. It usually says I'm missing a '{', but I can't see that I am...

What am I doing wrong?
Any assistance would be appreciated...
Sep 2 '11 #1
1 5921
CroCrew
564 Recognized Expert Contributor
This is a asp.net question not a Classic ASP question.

CroCrew~
Nov 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
4636
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide with the javascript in a toggle fashion. the problem is a know very little javascript and have become incredibly frustrated because i went ahead...
3
2938
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and it's easy to get something wrong. If the browser does not support the required features, I want it to generate a completely static page with the...
4
7990
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers) document.layers.visibility = 'visible'; else if (document.all) { document.all.style.visibility = 'visible';
4
8719
by: itunes66 | last post by:
how can i do this i already have a function to show/hide elements with one link but how can i show/hide multiple elements here is the script function obj_ref(object) { if (document.getElementById) { return document.getElementById(object);
3
7713
by: | last post by:
I'm using the DataList and GridView controls, and I am trying to wrap my head around the problem of conditionally showing or hiding cells/cell content based on the presence or absence of DB data. I am finding this sort of problem by far the most annoying part about working with ASP.NET controls. What I want is to know how to do three...
1
16734
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms...
1
4155
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. I don`t want to change the way i have used to show and hide layers. check down code :- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
1991
by: nubianqnn | last post by:
Hello All, I am stumped on a function to show/hide drop down elements based on a user's selection. If a user selects a second item from the first dropdown list, then I want to show a related dropdown with two options. If a user selects the second option from the second dropdown, then I want to show a data field. Somehow this is not working...
4
6744
by: nubianqnn | last post by:
I am stumped on a function to show/hide drop down elements based on a user's selection. If a user selects a second item from the first dropdown list, then I want to show a related dropdown with two options. If a user selects the second option from the second dropdown, then I want to show a data field. Somehow this is not working quite right. I am...
4
2631
by: metaphysics | last post by:
I searched forever to find this, but I didn't have any luck. Here's what I want to do: I want to have an image that when you click on it, it shows/hides content. I also want that image to change when you click on it. Basically, I want the content to show until you click the 'minus' image, and when that happens, I want the content to...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.