Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How do i hide and or display some content on a page

    Hello guys, i need help on the following:

    1. I want to use a "variable" passed from a URL [a] to select content on the destination page [b]. see example below:
    2. For example, say I want to pass "P2" from the URL and use it the DISPLAY option # **2** only below. therefore, only the info in **2** should be displayed the others should not show up on the page
    3. what should i do on the code behind page?

    [a]
    *****************************
    destinationMemberpage.aspx?id="P2"
    *****************************
    [b]
    *********************************
    **1**
    <div id="P1" class="mainNav">
    some HTML info here...
    </div>

    **2**
    <div id="P2" class="mainNav">
    some HTML info here...
    </div>

    **3**
    <div id="P3" class="mainNav">
    some HTML info here...
    </div>
    *********************************

    In a nut shell what it is... i have a page where i need to display a different Navigation Bar for different User Types. Thanks.

  • #2
    New Coder
    Join Date
    Jul 2011
    Location
    Chennai, India
    Posts
    23
    Thanks
    0
    Thanked 5 Times in 5 Posts
    There's no need to do it the code behind. You can achive it using JS.

    Hope, this'll help you
    Code:
    	 var url = window.location.toString();
    	 url.match(/\?(.+)$/);
    	 var params = RegExp.$1;
    	 var params = params.split("&");
    	 var queryStringList = {};
    	 
    	 for(var i=0;i<params.length;i++)
    	 {
    	 	var tmp = params[i].split("=");
    	 	queryStringList[tmp[0]] = unescape(tmp[1]);
    	 }
    	 var page='none';
    	 for(var i in queryStringList)
    	{
    		if(i=='id')
    		   page=queryStringList[i];
    	}
    
    	if(page=='P1')
    	//show div1, hide div2
    	else
    	//show div2, hide div1
    Use the above script in either one of the functions
    window.load or $(document).ready()
    Last edited by nanda.t; 01-19-2012 at 12:19 PM.

  • Users who have thanked nanda.t for this post:

    robuc (01-21-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks Nanda.t, i will give this a try.

  • #4
    New Coder
    Join Date
    Sep 2011
    Location
    Omaha, NE
    Posts
    49
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Look into Jquery, that will give you an even EASIER solution and faster.
    Web Design Omaha Ne
    Hold yourself responsible for a higher standard than anybody expects of you. Never excuse yourself.
    - Henry Ward Beecher

  • Users who have thanked Divinityfound for this post:

    robuc (01-27-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    97
    Thanks
    1
    Thanked 13 Times in 13 Posts
    you are doing this in asp.net? what language are you using and what program are you using to build it.

  • Users who have thanked sean3838 for this post:

    robuc (01-27-2012)

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sean3838 View Post
    you are doing this in asp.net? what language are you using and what program are you using to build it.
    Yes, i am doing it in ASP.NET...C#

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Divinityfound View Post
    Look into Jquery, that will give you an even EASIER solution and faster.
    You are right, i found some jquery that worked. Thanks.

  • #8
    New Coder
    Join Date
    Jan 2012
    Posts
    97
    Thanks
    1
    Thanked 13 Times in 13 Posts
    If you are using a div you need to use javascript like said above. Since you are using C# you need to use the RegisterStartupScript:

    Code:
    Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('G2').style.visibility = 'visible';" ,true);
    just change the element ID and visibility as needed. Hope this helps

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    jQuery is a ridiculous amount of code to use simply for showing and hiding content. You can do it in a dozen lines of easy to read JavaScript without jQuery instead of using the 40k+ of jQuery and a half dozen lines of not so easy to read JavaScript to call the library.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    jQuery is a ridiculous amount of code to use simply for showing and hiding content. You can do it in a dozen lines of easy to read JavaScript without jQuery instead of using the 40k+ of jQuery and a half dozen lines of not so easy to read JavaScript to call the library.
    Amen to that, people seem to think that jQuery is the be all and end all solution to any Javascript issue. When you're developing for a bandwidth intense environment (eg, the majority of mobile users) you quickly learn that unless you're doing very fancy stuff it's almost invariably better to either write your on JS or strip down the jQuery library to what you need!

    For instance, sean3838's example shows this quite well, compare his line of code to the entire of the jQuery library...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •