Click here to Skip to main content
12,896,833 members (59,260 online)
Rate this:
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-[^]
on forgot password Link Toggle will appear.but on Submit Button it is Disappearing.
               <td class="style4" colspan="3">
               <a href="#" id="showmenu">Forgot Password</a>
                   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<div id="content_div" style="display:none">
    <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>



$("#showmenu").click(function () {

reffered this[^]
but still not working
Posted 13-Dec-12 0:32am
Updated 14-Dec-12 1:22am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<pre lang="cs">$(function () {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(function (args, sender) {
            $(function () {
function showHide()
  $("#showmenu").click(function () {
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

<head runat="server">
    <script type='text/javascript' src="jquery-1.4.1.min.js">
    <style type="text/css">
            display: none;
    <script type="text/javascript">
        $(function() {
            $("#Link1").click(function(evt) {
                if ($('#panelText').hasClass('panel')) {
                    $('#PanelState').attr('value', 'true');
                } else {
                    $('#PanelState').attr('value', 'false');
        $(document).ready(function() {
            if ($('#PanelState').attr('value') == 'false') {
    <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"  />
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Use this following code.

$('#btnNext').click(function(e) {

or try like this.

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

Surendra0x2 13-Dec-12 8:11am
Where to add this in script?can u plz help?
Surendra0x2 13-Dec-12 12:08pm
I tried Both Sir But Sorry to say Both tricks not working :|
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.
Surendra0x2 13-Dec-12 13:43pm
i did this as he suggested
but still its not working :(

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2017
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