473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Hide using a div tab

I have an aspx page that contains a drop down and 3 divs and lots of other
stuff. I'd like to hide the divs depending on which option from the drop down
is selected. It works fine until I do a postback then all 3 divs are visible.

When the page initially loads I see just the div corresponding to the
default value in the ddl. Prior to a postback the display works as intended
but once a postback occurs all 3 divs are visible until I make another
selection on the ddl.

Code is below. As you will see I try to stay away from javascript but would
really like to avoid a postback here.

Thanks

Code behind
Protected WithEvents bodytag As HtmlGenericControl
PageLoad
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")
aspx page
<script language="JavaScript"> function toggleDiv() {
div1 = document.getElementById('divAssessment');
div2 = document.getElementById('divNC');
div3 = document.getElementById('divDesignComments');
DDL = document.getElementById('ddlSearch');
if (DDL.selectedIndex == 0) {
div1.style.visibility = 'visible';
div1.style.display = 'block';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 1) {
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'visible';
div2.style.display = 'block';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 2)
{
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'visible';
div3.style.display = 'block';
}
}

</script>

<body runat="server" id="bodytag">

<div >...

Nov 19 '05 #1
5 2814
What you need here is a call to the javascript function toggleDiv, after the
page is loaded in broswer

try
Page.RegisterStartupScript("<script>toggleDiv();</script>");

"Mardy" wrote:
I have an aspx page that contains a drop down and 3 divs and lots of other
stuff. I'd like to hide the divs depending on which option from the drop down
is selected. It works fine until I do a postback then all 3 divs are visible.

When the page initially loads I see just the div corresponding to the
default value in the ddl. Prior to a postback the display works as intended
but once a postback occurs all 3 divs are visible until I make another
selection on the ddl.

Code is below. As you will see I try to stay away from javascript but would
really like to avoid a postback here.

Thanks

Code behind
Protected WithEvents bodytag As HtmlGenericControl
PageLoad
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")
aspx page
<script language="JavaScript"> function toggleDiv() {
div1 = document.getElementById('divAssessment');
div2 = document.getElementById('divNC');
div3 = document.getElementById('divDesignComments');
DDL = document.getElementById('ddlSearch');
if (DDL.selectedIndex == 0) {
div1.style.visibility = 'visible';
div1.style.display = 'block';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 1) {
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'visible';
div2.style.display = 'block';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 2)
{
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'visible';
div3.style.display = 'block';
}
}

</script>

<body runat="server" id="bodytag">

<div >...

Nov 19 '05 #2
Awsome, that does it.

Thanks... but why does the initial page load work but not the postback?

"Sreejith Ram" wrote:
What you need here is a call to the javascript function toggleDiv, after the
page is loaded in broswer

try
Page.RegisterStartupScript("<script>toggleDiv();</script>");

"Mardy" wrote:
I have an aspx page that contains a drop down and 3 divs and lots of other
stuff. I'd like to hide the divs depending on which option from the drop down
is selected. It works fine until I do a postback then all 3 divs are visible.

When the page initially loads I see just the div corresponding to the
default value in the ddl. Prior to a postback the display works as intended
but once a postback occurs all 3 divs are visible until I make another
selection on the ddl.

Code is below. As you will see I try to stay away from javascript but would
really like to avoid a postback here.

Thanks

Code behind
Protected WithEvents bodytag As HtmlGenericControl
PageLoad
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")
aspx page
<script language="JavaScript"> function toggleDiv() {
div1 = document.getElementById('divAssessment');
div2 = document.getElementById('divNC');
div3 = document.getElementById('divDesignComments');
DDL = document.getElementById('ddlSearch');
if (DDL.selectedIndex == 0) {
div1.style.visibility = 'visible';
div1.style.display = 'block';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 1) {
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'visible';
div2.style.display = 'block';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 2)
{
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'visible';
div3.style.display = 'block';
}
}

</script>

<body runat="server" id="bodytag">

<div >...

Nov 19 '05 #3
I can only make a guess without seeing code

is there code hiding/showing divs at server side ? if so is it in "if
(!Page.IsPostBack)" ?
"Mardy" wrote:
Awsome, that does it.

Thanks... but why does the initial page load work but not the postback?

"Sreejith Ram" wrote:
What you need here is a call to the javascript function toggleDiv, after the
page is loaded in broswer

try
Page.RegisterStartupScript("<script>toggleDiv();</script>");

"Mardy" wrote:
I have an aspx page that contains a drop down and 3 divs and lots of other
stuff. I'd like to hide the divs depending on which option from the drop down
is selected. It works fine until I do a postback then all 3 divs are visible.

When the page initially loads I see just the div corresponding to the
default value in the ddl. Prior to a postback the display works as intended
but once a postback occurs all 3 divs are visible until I make another
selection on the ddl.

Code is below. As you will see I try to stay away from javascript but would
really like to avoid a postback here.

Thanks

Code behind
Protected WithEvents bodytag As HtmlGenericControl
PageLoad
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")
aspx page
<script language="JavaScript"> function toggleDiv() {
div1 = document.getElementById('divAssessment');
div2 = document.getElementById('divNC');
div3 = document.getElementById('divDesignComments');
DDL = document.getElementById('ddlSearch');
if (DDL.selectedIndex == 0) {
div1.style.visibility = 'visible';
div1.style.display = 'block';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 1) {
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'visible';
div2.style.display = 'block';
div3.style.visibility = 'hidden';
div3.style.display = 'none';
}

if (DDL.selectedIndex == 2)
{
div1.style.visibility = 'hidden';
div1.style.display = 'none';
div2.style.visibility = 'hidden';
div2.style.display = 'none';
div3.style.visibility = 'visible';
div3.style.display = 'block';
}
}

</script>

<body runat="server" id="bodytag">

<div >...

Nov 19 '05 #4
yes
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")

i have these two lines in between that if stmt but I tried both in and
outside that if stmt and saw no difference.

Thanks
"Sreejith Ram" wrote:
I can only make a guess without seeing code

is there code hiding/showing divs at server side ? if so is it in "if
(!Page.IsPostBack)" ?
"Mardy" wrote:
Awsome, that does it.

Thanks... but why does the initial page load work but not the postback?

"Sreejith Ram" wrote:
What you need here is a call to the javascript function toggleDiv, after the
page is loaded in broswer

try
Page.RegisterStartupScript("<script>toggleDiv();</script>");

"Mardy" wrote:

> I have an aspx page that contains a drop down and 3 divs and lots of other
> stuff. I'd like to hide the divs depending on which option from the drop down
> is selected. It works fine until I do a postback then all 3 divs are visible.
>
> When the page initially loads I see just the div corresponding to the
> default value in the ddl. Prior to a postback the display works as intended
> but once a postback occurs all 3 divs are visible until I make another
> selection on the ddl.
>
> Code is below. As you will see I try to stay away from javascript but would
> really like to avoid a postback here.
>
> Thanks
>
> Code behind
> Protected WithEvents bodytag As HtmlGenericControl
> PageLoad
> ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
> bodytag.Attributes.Add("onload", "return toggleDiv()")
>
>
> aspx page
> <script language="JavaScript"> function toggleDiv() {
> div1 = document.getElementById('divAssessment');
> div2 = document.getElementById('divNC');
> div3 = document.getElementById('divDesignComments');
> DDL = document.getElementById('ddlSearch');
> if (DDL.selectedIndex == 0) {
> div1.style.visibility = 'visible';
> div1.style.display = 'block';
> div2.style.visibility = 'hidden';
> div2.style.display = 'none';
> div3.style.visibility = 'hidden';
> div3.style.display = 'none';
> }
>
> if (DDL.selectedIndex == 1) {
> div1.style.visibility = 'hidden';
> div1.style.display = 'none';
> div2.style.visibility = 'visible';
> div2.style.display = 'block';
> div3.style.visibility = 'hidden';
> div3.style.display = 'none';
> }
>
> if (DDL.selectedIndex == 2)
> {
> div1.style.visibility = 'hidden';
> div1.style.display = 'none';
> div2.style.visibility = 'hidden';
> div2.style.display = 'none';
> div3.style.visibility = 'visible';
> div3.style.display = 'block';
> }
> }
>
> </script>
>
> <body runat="server" id="bodytag">
>
> <div >...
>

Nov 19 '05 #5
Well,my guess was that your onload=togglediv() is not working the first time
or in postbacks.. I meant you may have some other server side code to hide
div, like below ..

if(!Page.PostBack)
{
if(somevalue="0")
{
div1.attributes.add("style","visibility:none") ;
div1.attributes.add("style","visibility:hidden") ;

}
}

Any case the bottmline is, if one need to access the HTML elements using
javascript when the page loads, use Page.RegisterStartupScript ... :)

"Mardy" wrote:
yes
ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
bodytag.Attributes.Add("onload", "return toggleDiv()")

i have these two lines in between that if stmt but I tried both in and
outside that if stmt and saw no difference.

Thanks
"Sreejith Ram" wrote:
I can only make a guess without seeing code

is there code hiding/showing divs at server side ? if so is it in "if
(!Page.IsPostBack)" ?
"Mardy" wrote:
Awsome, that does it.

Thanks... but why does the initial page load work but not the postback?

"Sreejith Ram" wrote:

> What you need here is a call to the javascript function toggleDiv, after the
> page is loaded in broswer
>
> try
> Page.RegisterStartupScript("<script>toggleDiv();</script>");
>
>
>
> "Mardy" wrote:
>
> > I have an aspx page that contains a drop down and 3 divs and lots of other
> > stuff. I'd like to hide the divs depending on which option from the drop down
> > is selected. It works fine until I do a postback then all 3 divs are visible.
> >
> > When the page initially loads I see just the div corresponding to the
> > default value in the ddl. Prior to a postback the display works as intended
> > but once a postback occurs all 3 divs are visible until I make another
> > selection on the ddl.
> >
> > Code is below. As you will see I try to stay away from javascript but would
> > really like to avoid a postback here.
> >
> > Thanks
> >
> > Code behind
> > Protected WithEvents bodytag As HtmlGenericControl
> > PageLoad
> > ddlSearch.Attributes.Add("onchange", "return toggleDiv()")
> > bodytag.Attributes.Add("onload", "return toggleDiv()")
> >
> >
> > aspx page
> > <script language="JavaScript"> function toggleDiv() {
> > div1 = document.getElementById('divAssessment');
> > div2 = document.getElementById('divNC');
> > div3 = document.getElementById('divDesignComments');
> > DDL = document.getElementById('ddlSearch');
> > if (DDL.selectedIndex == 0) {
> > div1.style.visibility = 'visible';
> > div1.style.display = 'block';
> > div2.style.visibility = 'hidden';
> > div2.style.display = 'none';
> > div3.style.visibility = 'hidden';
> > div3.style.display = 'none';
> > }
> >
> > if (DDL.selectedIndex == 1) {
> > div1.style.visibility = 'hidden';
> > div1.style.display = 'none';
> > div2.style.visibility = 'visible';
> > div2.style.display = 'block';
> > div3.style.visibility = 'hidden';
> > div3.style.display = 'none';
> > }
> >
> > if (DDL.selectedIndex == 2)
> > {
> > div1.style.visibility = 'hidden';
> > div1.style.display = 'none';
> > div2.style.visibility = 'hidden';
> > div2.style.display = 'none';
> > div3.style.visibility = 'visible';
> > div3.style.display = 'block';
> > }
> > }
> >
> > </script>
> >
> > <body runat="server" id="bodytag">
> >
> > <div >...
> >

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Doug van Vianen | last post by:
Hi, I am using Choice to provide a dropdown menu in an Applet. I create the Choice and then need to hide it until it is needed and then show it. I use c.hide() and c.show() where 'c' is the...
5
by: Steve | last post by:
Visual Studio 2003 C# Windows: I have a tree view control as my main menu control down the left side of my application. This has 2 Parent Nodes on it (Jobs and Employees). beneath these 2 main...
3
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...
2
by: | last post by:
I have a page where I have 3 combo boxes listed in a column. sort of like: combo1 combo2 combo3 Based on which one is clicked, the others are supposed to hide (i.e. combobox.visible =...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
3
by: toodi4 | last post by:
I'm using a javascript that hides and unhides text based on a button click. It works great across static fields on a form. The problem I have is that I'm trying to hide and unhide various fields...
18
by: Liquidtouch | last post by:
I have been searching on this for awhile and cant find anything and playing around with it got me no where. I will start with what I am after and then explain what I have. I have a table with 3...
6
by: Doogie | last post by:
Hi I have an img control I am trying to hide upon certain types of commands in my code behind. When to hide it is directly tied to a asp:dropdownlist control. So depending on what the user...
2
by: richard | last post by:
In using the simple code below, how do I tell it NOT to hide a division when the link is clicked on if that division is already visible? would it be as simple as using a 2nd function and setting...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.