G
Guest
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 >...
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 >...