I have a pretty nifty JavaScript toggle that I found on some site, and customized for use on my ASP.NET (
VB.NET) site. It works great, except for one thing: when a user causes a client-side postback because AutoPostBack is set to true on the ASP.NET page's web control, the current toggled state goes away, and that toggle pane is closed (DIPLAY:NONE;).
I need for the toggled window to maintain whatever state it's in when a user causes a client-side postback on the form. Does anyone know how to do this? I'd appreciate any help. Here is my code:
JavaScript Code
//Source:
http://blog.movalog.com/a/javascript-toggle-visibility/, scroll down to Neeraj Maurya
function swaptabs (showthis,hidethis) {//begin function
var style2 = document.getElementById(showthis).style;
style2.display = "block";
var style3 = document.getElementById(hidethis).style;
style3.display = "none";
}//end function
ASP.NET Code: (only section referenced)
Code:
<form id="formContactInfo" name="formContactInfo" enctype="multipart/form-data" runat="server">
<table align="center" id="ContactInfoToggle">
<tr>
<td colspan="2" align="center">Contact Info</td>
</tr>
<tr>
<td colspan="2" align="center">
<div id="Section-closed" name="Section-closed" style="DISPLAY: block">
<a href="javascript:swaptabs('Section-open','Section-closed');">
[+]<strong> Add Section</strong>
</a>
</div>
</td>
</tr>
</table>
<div id="Section-open" name="Section-open" style="DISPLAY: none">
<table align="center" id="ContactInfo">
<tr>
<td colspan="2" align="center">
<a href="javascript:swaptabs('Section-closed','Section-open');">
[-] Collapse Section
</a>
</td>
</tr>
<tr>
<td align="right" width="20%">
Full Name
</td>
<td width="80%">
<asp:Textbox ID="txtFullName" columns="20" MaxLength="50" runat="server" />
</td>
</tr>
</table>
</div>
</form>