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 >... 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 >...
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 >...
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 >...
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 >... >
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 >... > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
|
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...
|
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...
| |