Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

show a panel using the jquery by click the below link

ASP
<a class="flip1" href="#" title="Comment" style="color:#CEF"><img src="/image/history-button.gif"/></a>


the jquery as below,
JavaScript
$(document).ready(function () {
                 $(".flip1").click(function () {
                     $("#panel").slideToggle("slow");
                 });
             });


My problem is disappear the div when click other button inside a update panel.

how to avoid this?

[Edit]Code block added[/Edit]
Posted
Updated 3-Sep-17 17:46pm
v2

Yes, it'll disappear.

As I can see onclick flip1 of flip control you are showing the panel. when entire page will be posted back to the server, it'll recreate it's shape. To avoid that you should use Update Panel[^] for the partial update/rendering of the page.
OR
A .NET button causes a postback to the server which reconstructs the entire page and sends it back to the browser. Since the open method is called clientside, the change is not registered in the viewstate of the page. If you want to have it remember if it was open or closed across postbacks, use a hidden field in the page. When you open the dialog with jQuery, set the value of the hidden field (must be runat="server" hidden field).
Add a handler to the load event of the page (client-side) that checks the value of the hidden field and shows the dialog if the value is correct.
Original Source here[^].

--Amit
 
Share this answer
 
Comments
Sk. Tajbir 23-Feb-13 9:36am    
nice.. 5+
Important thing you should know while using Jquery is PostBack property
When postback occurse JQuery code will get its original values..
So you should prevent postback to see the functionality of it..

ASP.NET
<asp:button id="Button1" runat="server" text="Button" xmlns:asp="#unknown" /> 

JQuery code below..
JavaScript
$(document).ready(function () {
             $(".flip1").click(function () 
             {
                        $("#panel").slideToggle("slow");
              });
            $("#Button1").click(function (e) // button inside update panel
              {
                 e.preventDefault();
                });
 
   });


Where e.preventDefault() will avoid paostback.. So when you are using buttons use e.preventDefault() to prevent postback ( If postback is no necessory )..
 
Share this answer
 
v2

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