Click here to Skip to main content
15,886,004 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a div that I initially set to display:none but i show and hide the div after a click on a link.
The problem is that I have Button that causes a postback. Every time i click the button the div goes back to hiding, which i don't want of course. How can I make the div persist it's state when a postback occurs.
The div is inside a updatepanel.
Here is the Url-http://www.surendrakumarverma.com/userlogin.aspx[^]
on forgot password Link Toggle will appear.but on Submit Button it is Disappearing.
ASP.NET
<tr>
               <td class="style4" colspan="3">
               <a href="#" id="showmenu">Forgot Password</a>
                   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                   
                   <ContentTemplate>

<div id="content_div" style="display:none">
                   

<table>
<tr><td>
    <asp:TextBox ID="TextBox3" CssClass="textbox" runat="server"></asp:TextBox></td><td>
        <asp:Button ID="Button2" runat="server" CssClass="send" Text="Button" 
            CausesValidation="False" onclick="Button2_Click" 
             />
        <asp:Label ID="Label4" runat="server" ></asp:Label>
             
             </td></tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
                   </td>
           </tr>


Script-

JavaScript
<script>


$("#showmenu").click(function () {
$("#content_div").toggle("slow");

});    
</script>


reffered this
http://blog.dreamlabsolutions.com/post/2009/02/24/jQuery-document-ready-and-ASP-NET-Ajax-asynchronous-postback.aspx[^]
but still not working
Posted
Updated 14-Dec-12 1:22am
v7

XML
<script>
showHide();
<pre lang="cs">$(function () {
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        prm.add_endRequest(function (args, sender) {
            $(function () {
                showHide();
            });
        });

    });

function showHide()
{
  $("#showmenu").click(function () {
     $("#content_div").toggle("slow");
  }); 
}
</script>
 
Share this answer
 
Comments
Surendra0x2 13-Dec-12 8:07am    
When i pasted this in header then it is showing error expected expression
sir can u check it ?
Parwej Ahamad 13-Dec-12 8:12am    
pre lang="cs"> remove this from code, it was mistaken inserted into the sample code
Surendra0x2 13-Dec-12 8:18am    
Sir,It's not working On first time page load it is showing toogle div but on Button click it is hiding means on postback and afterpostback when i'm hovering on link it is showing and hiding div.
ASP.NET
<head runat="server">
    <title></title>

    <script type='text/javascript' src="jquery-1.4.1.min.js">
    </script>

    <style type="text/css">
        .panel
        {
            display: none;
        }
    </style>

    <script type="text/javascript">
        $(function() {
            $("#Link1").click(function(evt) {
                evt.preventDefault();
                $('#panelText').slideToggle('slow');
                if ($('#panelText').hasClass('panel')) {
                    $('#PanelState').attr('value', 'true');
                } else {
                    $('#PanelState').attr('value', 'false');
                }                
             });
        });

        $(document).ready(function() {
            if ($('#PanelState').attr('value') == 'false') {
                $('#panelText').addClass('panel');
            }
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:hiddenfield id="PanelState" runat="server" value="false"  />
    <asp:hyperlink id="Link1" runat="server" navigateurl="#" >SlideToggle
    </asp:hyperlink><br />
    <asp:panel id="panelText" runat="server" >
        Some text</asp:panel>
    <asp:button id="button1" runat="server" text="Postback"  />
    </form>
</body>
</html>
 
Share this answer
 
v3
Hi,

Use this following code.

C#
$('#btnNext').click(function(e) {
        e.preventDefault();
    });


or try like this.

C#
$('#btnNext').click(function() {
        return false;
    });


Thanks
 
Share this answer
 
Comments
Surendra0x2 13-Dec-12 8:11am    
Where to add this in script?can u plz help?
[no name] 13-Dec-12 9:45am    
Change your code to like this.

<script>


$("#showmenu").click(function () {
$("#content_div").toggle("slow");
return false;

});
</script>

or try like this.

<script>


$("#showmenu").click(function (e) {
$("#content_div").toggle("slow");
e.preventDefault();


});
</script>

If this also don't work then please let me know.
Surendra0x2 13-Dec-12 12:08pm    
I tried Both Sir But Sorry to say Both tricks not working :|
[no name] 13-Dec-12 12:48pm    
1st of all remove the onclick event from the button and code behind if that is not necessary. Tell me the work of the onclick event that you have added to your button.
Surendra0x2 13-Dec-12 12:59pm    
i'm creating forgot password and on Button click i want to send the password to the user via mail so Sir Button click is main thing here.

My Textbox and Button is inside update panel when i click on Button the toggeled Div Disappears this which i want to appear after partial postback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900