Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
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.
<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-
 
 
<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 13-Dec-12 0:32am
Edited 14-Dec-12 1:22am
v7
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<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>
  Permalink  
Comments
Surendra0x2 at 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 at 13-Dec-12 8:12am
   
pre lang="cs"> remove this from code, it was mistaken inserted into the sample code
Surendra0x2 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Use this following code.
 
$('#btnNext').click(function(e) {
        e.preventDefault();
    });
 
or try like this.
 
$('#btnNext').click(function() {
        return false;
    });
 
Thanks
  Permalink  
Comments
Surendra0x2 at 13-Dec-12 8:11am
   
Where to add this in script?can u plz help?
Surendra0x2 at 13-Dec-12 12:08pm
   
I tried Both Sir But Sorry to say Both tricks not working :|
Surendra0x2 at 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.
Surendra0x2 at 13-Dec-12 13:43pm
   
i did this as he suggested
http://blog.dreamlabsolutions.com/post/2009/02/24/jQuery-document-ready-and-ASP-NET-Ajax-asynchronous-postback.aspx
but still its not working :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<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>
 
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 220
1 ProgramFOX 120
2 Richard MacCutchan 100
3 kbrandwijk 90
4 ChauhanAjay 80
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100