...

View Full Version : How do i hide and or display some content on a page



robuc
01-18-2012, 01:50 PM
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.

nanda.t
01-19-2012, 01:07 PM
There's no need to do it the code behind. You can achive it using JS.

Hope, this'll help you


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()

robuc
01-20-2012, 12:55 PM
Thanks Nanda.t, i will give this a try.

Divinityfound
01-20-2012, 05:10 PM
Look into Jquery, that will give you an even EASIER solution and faster.

sean3838
01-26-2012, 06:35 AM
you are doing this in asp.net? what language are you using and what program are you using to build it.

robuc
01-27-2012, 09:38 PM
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
01-27-2012, 09:39 PM
Look into Jquery, that will give you an even EASIER solution and faster.

You are right, i found some jquery that worked. Thanks.

sean3838
01-27-2012, 10:07 PM
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:


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

felgall
01-27-2012, 10:43 PM
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.

RaymondBlink
02-07-2012, 09:56 PM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum