Click here to Skip to main content
15,943,008 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

I am using Jquery slideToggle function for hide div after click on server side button,when i click on button div hide but after page refresh it shows again. I want after click on button div should be hide.
I also used for this hide function but it's also not working.
Please Help Me.

Here My Code
Hints - #TenderReport Is a Div Id

$(document).ready(function () {
$("#<%=btnSearch.ClientID %>").click(function () {
$('#TenderReport').slideToggle();
//alert('Button clicked.');
});
});

Thanks Friends.
Posted

please try this code for hiding div with id TenderReport.

$(document).ready(function () {
     $("#<%=btnSearch.ClientID %>").click(function () {
           $('#TenderReport').hide(); 
          //alert('Button clicked.');
       });
   });
 
Share this answer
 
You are hiding the button on client side, so as you refresh the page div shows again. For your requirement you may use a panel instead of div.
ASP.NET
<asp:panel id="p1" runat="server" xmlns:asp="#unknown">
Your text
</asp:panel>
<asp:button id="btnHide" runat="server" text="Hide" onclick="btnHide_Click" xmlns:asp="#unknown" />

On click method:
C#
//to hide
p1.Visibility = false;

//to show
p1.Visibility = true;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-15 2:41am    
One little problem is that each click would cause postback; the solution is slow...
For some alternative, please see Solution 2.
—SA
Of course it shows again, because all the page is re-created from scratch and the scripts are executed exactly as the would do the first time. Basically, you could do two things: either store the data on states of all controls on the server side by sending this data via Ajax, or store this data locally using Web storage.

I don't want to discuss using postbacks and server-side processing "on every click". Such approach is already heavily abused on many sites and mostly only wastes traffic and irritates the users with numerous delays. Ajax is better because you transmit much less data and, in your particular case, you don't have to update anything on the page: it happens only on client side (exactly as you already achieved that), and the data transmitted via Ajax will only be taken into account in the ASP.NET generation of scripts on next page reload.

However, I would rather recommend the pure client-side approach, Web storage: http://en.wikipedia.org/wiki/Web_storage[^].

This approach is more universal. You separate concerns: the server-side behavior is not taken into account, and the server side is kept unaware of changed states of controls. This separation of implementation of features facilitates maintenance.

There are two aspects here. Firstly, use sessionStorage object, not localStorage. Secondly, to put all the states of all controls to storage at the same key and reduce ad hoc coding, you can use embedded JSON object. This is all explained in one section of my article, which comes with the source code which you can use as a complete sample implementation of this technique: JavaScript Calculator, 7. Dynamic Strict Mode Switching and Web Storage.

—SA
 
Share this answer
 
Comments
Arkadeep De 25-Jun-15 2:55am    
ya that solution will be slow. it is surely a better solution. and thanks though for sharing the knowledge about web storage. I didn't know about that.

Thanks again. :) (y)
Sergey Alexandrovich Kryukov 25-Jun-15 3:04am    
You are very welcome.
—SA

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