Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2012, 12:50 PM   PM User | #1
robuc
New Coder

 
Join Date: Jan 2012
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
robuc is an unknown quantity at this point
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.
robuc is offline   Reply With Quote
Old 01-19-2012, 12:07 PM   PM User | #2
nanda.t
New Coder

 
Join Date: Jul 2011
Location: Chennai, India
Posts: 23
Thanks: 0
Thanked 5 Times in 5 Posts
nanda.t is an unknown quantity at this point
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..
nanda.t is offline   Reply With Quote
Users who have thanked nanda.t for this post:
robuc (01-21-2012)
Old 01-20-2012, 11:55 AM   PM User | #3
robuc
New Coder

 
Join Date: Jan 2012
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
robuc is an unknown quantity at this point
Thanks Nanda.t, i will give this a try.
robuc is offline   Reply With Quote
Old 01-20-2012, 04:10 PM   PM User | #4
Divinityfound
New Coder

 
Join Date: Sep 2011
Location: Omaha, NE
Posts: 49
Thanks: 1
Thanked 6 Times in 5 Posts
Divinityfound is an unknown quantity at this point
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
Divinityfound is offline   Reply With Quote
Users who have thanked Divinityfound for this post:
robuc (01-27-2012)
Old 01-26-2012, 05:35 AM   PM User | #5
sean3838
New Coder

 
Join Date: Jan 2012
Posts: 90
Thanks: 1
Thanked 13 Times in 13 Posts
sean3838 is an unknown quantity at this point
you are doing this in asp.net? what language are you using and what program are you using to build it.
sean3838 is offline   Reply With Quote
Users who have thanked sean3838 for this post:
robuc (01-27-2012)
Old 01-27-2012, 08:38 PM   PM User | #6
robuc
New Coder

 
Join Date: Jan 2012
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
robuc is an unknown quantity at this point
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#
robuc is offline   Reply With Quote
Old 01-27-2012, 08:39 PM   PM User | #7
robuc
New Coder

 
Join Date: Jan 2012
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
robuc is an unknown quantity at this point
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.
robuc is offline   Reply With Quote
Old 01-27-2012, 09:07 PM   PM User | #8
sean3838
New Coder

 
Join Date: Jan 2012
Posts: 90
Thanks: 1
Thanked 13 Times in 13 Posts
sean3838 is an unknown quantity at this point
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
sean3838 is offline   Reply With Quote
Old 01-27-2012, 09:43 PM   PM User | #9
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 02-07-2012, 08:56 PM   PM User | #10
RaymondBlink
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
RaymondBlink is an unknown quantity at this point
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...
RaymondBlink is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:53 PM.


Advertisement
Log in to turn off these ads.